ConstraintCollection.RemoveAt(Int32) Metoda

Definice

Odebere Constraint objekt v zadaném indexu z kolekce.

public:
 void RemoveAt(int index);
public void RemoveAt (int index);
member this.RemoveAt : int -> unit
Public Sub RemoveAt (index As Integer)

Parametry

index
Int32

Index objektu, který Constraint se má odebrat.

Výjimky

Kolekce nemá omezení v tomto indexu.

Příklady

Následující příklad používá metodu IndexOf společně s metodou RemoveAt k odebrání omezení z objektu ConstraintCollection.

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 e As Exception
        ' Process exception and return.
        Console.WriteLine("Exception of type {0} occurred.", _
            e.GetType().ToString())
    End Try
End Sub

Poznámky

Metoda IndexOf vrátí index konkrétního Constraintobjektu .

Před použitím RemoveAt metody můžete použít metodu Contains k určení, zda kolekce obsahuje cíl Constraint, a metodu CanRemove k určení, zda Constraint lze odebrat .

Událost CollectionChanged nastane, pokud je omezení úspěšně odebráno.

Platí pro

Viz také