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
返回
true 如果集合包含指定的约束,则为 ;否则,为 false.
示例
以下示例确定指定ConstraintConstraintCollection在删除之前是否存在。
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 该方法来确定是否可以删除 a Constraint 。