ConstraintCollection.IndexOf Metoda

Definicja

Pobiera indeks określonego Constraintelementu .

Przeciążenia

IndexOf(Constraint)

Pobiera indeks określonego Constraintelementu .

IndexOf(String)

Pobiera indeks określonego Constraint przez nazwę.

IndexOf(Constraint)

Źródło:
ConstraintCollection.cs
Źródło:
ConstraintCollection.cs
Źródło:
ConstraintCollection.cs

Pobiera indeks określonego Constraintelementu .

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

Parametry

constraint
Constraint

Element do wyszukania Constraint .

Zwraca

Indeks Constraint oparty na zerze elementu , jeśli znajduje się w kolekcji; w przeciwnym razie wartość -1.

Przykłady

W poniższym przykładzie użyto IndexOf metody , aby zwrócić indeks klasy Constraint. Indeks jest przekazywany do Contains metody przed jej usunięciem, aby określić, czy kolekcja zawiera ograniczenie.

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

Uwagi

Użyj metody , IndexOf aby zwrócić indeks do użycia z Contains metodą lub Remove .

Zobacz też

Dotyczy

IndexOf(String)

Źródło:
ConstraintCollection.cs
Źródło:
ConstraintCollection.cs
Źródło:
ConstraintCollection.cs

Pobiera indeks określonego Constraint przez nazwę.

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

Parametry

constraintName
String

Nazwa elementu Constraint.

Zwraca

Indeks obiektu Constraint , jeśli znajduje się w kolekcji; w przeciwnym razie wartość -1.

Przykłady

W poniższym przykładzie użyto IndexOf metody , aby zwrócić indeks klasy Constraint. Indeks jest przekazywany do Contains metody w celu określenia, czy kolekcja zawiera ograniczenie, przed jego usunięciem.

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

Uwagi

Użyj metody , IndexOf aby zwrócić indeks do użycia z Contains metodą lub Remove .

Zobacz też

Dotyczy