System.Data Namespace ConstraintCollection Class
Returns the index of the Constraint, specified by name.
[ VB ]
Overridable Overloads Public Function IndexOf ( _
ByVal constraintName As String _
) As Integer
[ C# ]
public virtual int IndexOf (
String constraintName
);
[ C++ ]
public: virtual int IndexOf (
String* constraintName
);
[ JScript ]
public function IndexOf (
constraintName : String
) : int
- constraintName
- The name of the Constraint.
The index of the Constraint if it is in the collection; otherwise, -1.
Use the IndexOf method to return an index to be used with either the Contains or Remove method.
The following example uses the IndexOf method to return the index of a Constraint. The index is passed to the Contains method to determine if the collection contains the constraint, before removing it.
private void RemoveConstraint ( ConstraintCollection myConstraints,
Constraint myConstraint ) {
try {
if ( myConstraints.Contains ( myConstraint.ConstraintName ) ) {
if ( myConstraints.CanRemove ( myConstraint ) ) {
myConstraints.RemoveAt (
myConstraints.IndexOf ( myConstraint.ConstraintName ) );
}
}
}
catch ( Exception myException ) {
Response.Write ( myException.Message );
}
}
Private Sub RemoveConstraint ( myConstraints As ConstraintCollection, _
myConstraint As Constraint )
Try
If myConstraints.Contains ( myConstraint.ConstraintName ) Then
If myConstraints.CanRemove ( myConstraint ) Then
myConstraints.RemoveAt _
( myConstraints.IndexOf ( myConstraint.ConstraintName ) )
End If
End If
Catch myException As Exception
Response.Write ( myException.Message )
End Try
End Sub |
|
C# |
VB |
ConstraintCollection Members ConstraintCollection.IndexOf Overload List Contains Remove CanRemove