Uredi

Deli z drugimi prek


ConstraintCollection.IndexOf Method

Definition

Gets the index of the specified Constraint.

Overloads

IndexOf(Constraint)

Gets the index of the specified Constraint.

IndexOf(String)

Gets the index of the Constraint specified by name.

IndexOf(Constraint)

Source:
ConstraintCollection.cs
Source:
ConstraintCollection.cs
Source:
ConstraintCollection.cs

Gets the index of the specified Constraint.

public:
 int IndexOf(System::Data::Constraint ^ constraint);
public int IndexOf (System.Data.Constraint? constraint);
public int IndexOf (System.Data.Constraint constraint);
member this.IndexOf : System.Data.Constraint -> int
Public Function IndexOf (constraint As Constraint) As Integer

Parameters

constraint
Constraint

The Constraint to search for.

Returns

The zero-based index of the Constraint if it is in the collection; otherwise, -1.

Examples

The following example uses the IndexOf method to return the index of a Constraint. The index is passed to the Contains method, before it is removed, to determine whether the collection contains the constraint.

private void RemoveConstraint(
    ConstraintCollection constraints, Constraint constraint)
{
    try
    {
        if(constraints.Contains(constraint.ConstraintName))
        {
            if(constraints.CanRemove(constraint))
            {
                constraints.RemoveAt(constraints.IndexOf(constraint));
            }
        }
    }
    catch(Exception e)
    {
        // Process exception and return.
        Console.WriteLine("Exception of type {0} occurred.",
            e.GetType());
    }
}
Private Sub RemoveConstraint _
    (constraints As ConstraintCollection, constraint As Constraint)
    Try
        If constraints.Contains(constraint.ConstraintName) Then
            If constraints.CanRemove(constraint) Then
                constraints.RemoveAt _
                (constraints.IndexOf(constraint))
            End If
        End If

    Catch e As Exception
    ' Process exception and return.
        Console.WriteLine("Exception of type {0} occurred.", _
            e.GetType().ToString())
    End Try
End Sub

Remarks

Use the IndexOf method to return an index to be used with either the Contains or Remove method.

See also

Applies to

IndexOf(String)

Source:
ConstraintCollection.cs
Source:
ConstraintCollection.cs
Source:
ConstraintCollection.cs

Gets the index of the Constraint specified by name.

public:
 int IndexOf(System::String ^ constraintName);
public:
 virtual int IndexOf(System::String ^ constraintName);
public int IndexOf (string? constraintName);
public int IndexOf (string constraintName);
public virtual int IndexOf (string constraintName);
member this.IndexOf : string -> int
abstract member IndexOf : string -> int
override this.IndexOf : string -> int
Public Function IndexOf (constraintName As String) As Integer
Public Overridable Function IndexOf (constraintName As String) As Integer

Parameters

constraintName
String

The name of the Constraint.

Returns

The index of the Constraint if it is in the collection; otherwise, -1.

Examples

The following example uses the IndexOf method to return the index of a Constraint. The index is passed to the Contains method to determine whether the collection contains the constraint, before removing it.

private void RemoveConstraint(
    ConstraintCollection constraints, Constraint constraint)
{
    try
    {
        if(constraints.Contains(constraint.ConstraintName))
        {
            if(constraints.CanRemove(constraint))
            {
                constraints.RemoveAt(
                    constraints.IndexOf(constraint.ConstraintName));
            }
        }
    }
    catch(Exception e)
    {
        // Process exception and return.
        Console.WriteLine("Exception of type {0} occurred.",
            e.GetType());
    }
}
Private Sub RemoveConstraint _
    (constraints As ConstraintCollection, constraint As Constraint)

    Try
        If constraints.Contains(constraint.ConstraintName) Then
            If constraints.CanRemove(constraint) Then
                constraints.RemoveAt _
                (constraints.IndexOf(constraint.ConstraintName))
            End If
        End If

    Catch ex As Exception
    ' Process exception and return.
        Console.WriteLine(ex.Message)
    End Try
End Sub

Remarks

Use the IndexOf method to return an index to be used with either the Contains or Remove method.

See also

Applies to