ConstraintCollection.Contains(String) Metoda

Definice

Určuje, zda Constraint objekt určený názvem existuje v kolekci.

public:
 bool Contains(System::String ^ name);
public bool Contains (string? name);
public bool Contains (string name);
member this.Contains : string -> bool
Public Function Contains (name As String) As Boolean

Parametry

name
String

Omezení ConstraintName .

Návraty

truePokud kolekce obsahuje zadané omezení; v opačném případě . false

Příklady

Následující příklad určuje, zda zadaná Constraint existuje v před jeho odstraněním ConstraintCollection .

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

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

Poznámky

Contains Pomocí metody zjistěte, jestli zadaná Constraint hodnota existuje, než se ji pokusíte odebrat z kolekce. Můžete také použít metodu CanRemove k určení, zda Constraint lze odebrat.

Platí pro

Viz také