ConstraintCollection.IndexOf Metoda

Definice

Získá index zadaného Constraintobjektu .

Přetížení

IndexOf(Constraint)

Získá index zadaného Constraintobjektu .

IndexOf(String)

Získá index Constraint zadaného názvem.

IndexOf(Constraint)

Zdroj:
ConstraintCollection.cs
Zdroj:
ConstraintCollection.cs
Zdroj:
ConstraintCollection.cs

Získá index zadaného Constraintobjektu .

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

Hledaný Constraint výraz.

Návraty

Index objektu Constraint založeného na nule, pokud je v kolekci; v opačném případě hodnota -1.

Příklady

Následující příklad používá metodu IndexOf k vrácení indexu objektu Constraint. Index je předán Contains metodě před jeho odebráním, aby se zjistilo, zda kolekce obsahuje omezení.

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

Poznámky

Použijte metodu IndexOf k vrácení indexu, který se má použít s metodou Contains nebo Remove .

Viz také

Platí pro

IndexOf(String)

Zdroj:
ConstraintCollection.cs
Zdroj:
ConstraintCollection.cs
Zdroj:
ConstraintCollection.cs

Získá index Constraint zadaného názvem.

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

Název procesu Constraint.

Návraty

Index objektu , Constraint pokud je v kolekci; jinak hodnota -1.

Příklady

Následující příklad používá metodu IndexOf k vrácení indexu objektu Constraint. Index se předá Contains metodě , aby se zjistilo, jestli kolekce obsahuje omezení, a teprve potom ho odeberete.

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

Poznámky

Použijte metodu IndexOf k vrácení indexu, který se má použít s metodou Contains nebo Remove .

Viz také

Platí pro