ConstraintCollection.Contains(String) メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
名前で指定された 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を削除できるかどうかを判断することもできます。