ConstraintCollection.RemoveAt 方法
从集合中移除位于指定索引位置的 Constraint 对象。
**命名空间:**System.Data
**程序集:**System.Data(在 system.data.dll 中)
语法
声明
Public Sub RemoveAt ( _
index As Integer _
)
用法
Dim instance As ConstraintCollection
Dim index As Integer
instance.RemoveAt(index)
public void RemoveAt (
int index
)
public:
void RemoveAt (
int index
)
public void RemoveAt (
int index
)
public function RemoveAt (
index : int
)
参数
- index
要移除的 Constraint 的索引。
异常
异常类型 | 条件 |
---|---|
集合在此索引位置没有约束。 |
备注
IndexOf 方法返回特定 Constraint 的索引。
在使用 RemoveAt 方法之前,可以使用 Contains 方法来确定集合是否包含目标 Constraint,使用 CanRemove 方法来确定是否可以移除 Constraint。
如果成功移除约束,则会发生 CollectionChanged 事件。
示例
下面的示例使用 IndexOf 方法和 RemoveAt 方法从 ConstraintCollection 中移除约束。
Private Sub RemoveConstraint _
(constraints As ConstraintCollection, constraint As Constraint)
Try
If constraints.Contains(constraint.ConstraintName) Then
If constraints.CanRemove(constraint) Then
constraints.RemoveAt _
(constraints.IndexOf(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
private void RemoveConstraint(ConstraintCollection constraints,
Constraint constraint)
{
try
{
if(constraints.Contains(constraint.ConstraintName))
{
if(constraints.CanRemove(constraint))
{
constraints.RemoveAt(constraints.IndexOf(
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 命名空间
CanRemove
Contains
IndexOf