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 判断することもできます。

適用対象

こちらもご覧ください