ConstraintCollection.Contains(String) Yöntem

Tanım

Adla belirtilen nesnenin Constraint koleksiyonda var olup olmadığını gösterir.

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

Parametreler

name
String

Kısıtlamanın ConstraintName .

Döndürülenler

true koleksiyon belirtilen kısıtlamayı içeriyorsa; aksi takdirde , false.

Örnekler

Aşağıdaki örnek, belirtilen Constraint öğesinin silinmeden önce içinde ConstraintCollection mevcut olup olmadığını belirler.

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

Açıklamalar

Belirtilen Contains öğeyi Constraint koleksiyondan kaldırmaya çalışmadan önce mevcut olup olmadığını belirlemek için yöntemini kullanın. Bir kaldırılıp CanRemove kaldırılamayacağını belirlemek için yöntemini de kullanabilirsinizConstraint.

Şunlara uygulanır

Ayrıca bkz.