ConstraintCollection.Contains 方法
指示集合中是否存在按名称指定的 Constraint 对象。
**命名空间:**System.Data
**程序集:**System.Data(在 system.data.dll 中)
语法
声明
Public Function Contains ( _
name As String _
) As Boolean
用法
Dim instance As ConstraintCollection
Dim name As String
Dim returnValue As Boolean
returnValue = instance.Contains(name)
public bool Contains (
string name
)
public:
bool Contains (
String^ name
)
public boolean Contains (
String name
)
public function Contains (
name : String
) : boolean
参数
- name
约束的 ConstraintName。
返回值
如果集合包含指定的约束,则为 true;否则为 false。
备注
在尝试从集合中移除指定的 Constraint 之前使用 Contains 方法来确定它是否存在。还可以使用 CanRemove 方法来确定是否可以移除 Constraint。
示例
下面的示例在删除指定的 Constraint 之前先确定它是否存在于 ConstraintCollection 中。
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 {0} occurred.", _
e.GetType().ToString())
End Try
End Sub
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());
}
}
平台
Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
.NET Compact Framework
受以下版本支持:2.0、1.0
请参见
参考
ConstraintCollection 类
ConstraintCollection 成员
System.Data 命名空间
Remove