Share via


ConstraintCollection.Contains(String) 메서드

정의

이름으로 지정된 Constraint개체가 컬렉션에 있는지 여부를 나타냅니다.

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

매개 변수

name
String

제약 조건의 ConstraintName입니다.

반환

컬렉션에 지정한 제약 조건이 있으면 true이고, 그렇지 않으면 false입니다.

예제

다음 예제에서는 지정된 Constraint 가 삭제되기 전에 에 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

설명

사용 된 Contains 컬렉션에서 제거 하려고 하기 전에 지정 된 Constraint 여부를 확인 하는 방법입니다. 메서드를 사용하여 를 CanRemove 제거할 수 있는지 여부를 Constraint 확인할 수도 있습니다.

적용 대상

추가 정보