ConstraintCollection.IndexOf Methode

Definitie

Hiermee haalt u de index van de opgegeven Constraint.

Overloads

Name Description
IndexOf(Constraint)

Hiermee haalt u de index van de opgegeven Constraint.

IndexOf(String)

Hiermee haalt u de index op van de Constraint opgegeven naam.

IndexOf(Constraint)

Hiermee haalt u de index van de opgegeven 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

De Constraint te zoeken.

Retouren

De op nul gebaseerde index van de Constraint index als deze zich in de verzameling bevindt; anders -1.

Voorbeelden

In het volgende voorbeeld wordt de IndexOf methode gebruikt om de index van een Constraint. De index wordt doorgegeven aan de Contains methode, voordat deze wordt verwijderd, om te bepalen of de verzameling de beperking bevat.

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

Opmerkingen

Gebruik de IndexOf methode om een index te retourneren die moet worden gebruikt met de Contains of Remove methode.

Zie ook

Van toepassing op

IndexOf(String)

Hiermee haalt u de index op van de Constraint opgegeven naam.

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

Parameters

constraintName
String

De naam van de Constraint.

Retouren

De index van de Constraint als deze zich in de verzameling bevindt; anders -1.

Voorbeelden

In het volgende voorbeeld wordt de IndexOf methode gebruikt om de index van een Constraint. De index wordt doorgegeven aan de Contains methode om te bepalen of de verzameling de beperking bevat, voordat deze wordt verwijderd.

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

Opmerkingen

Gebruik de IndexOf methode om een index te retourneren die moet worden gebruikt met de Contains of Remove methode.

Zie ook

Van toepassing op