ConstraintCollection.Item[] 属性

定义

从集合中获取指定的 Constraint

重载

Item[Int32]

从集合中获取位于指定索引位置的 Constraint

Item[String]

从具有指定名称的集合中获取 Constraint

Item[Int32]

Source:
ConstraintCollection.cs
Source:
ConstraintCollection.cs
Source:
ConstraintCollection.cs

从集合中获取位于指定索引位置的 Constraint

public:
 property System::Data::Constraint ^ default[int] { System::Data::Constraint ^ get(int index); };
public:
 virtual property System::Data::Constraint ^ default[int] { System::Data::Constraint ^ get(int index); };
public System.Data.Constraint this[int index] { get; }
public virtual System.Data.Constraint this[int index] { get; }
member this.Item(int) : System.Data.Constraint
Default Public ReadOnly Property Item(index As Integer) As Constraint
Default Public Overridable ReadOnly Property Item(index As Integer) As Constraint

参数

index
Int32

要返回的约束的索引。

属性值

指定索引处的 Constraint

例外

索引值大于集合中的项目数。

示例

以下示例从 ConstraintCollection获取每个 Constraint

private void GetConstraint(DataTable table)
{
    for(int i = 0; i < table.Constraints.Count; i++)
    {
        Console.WriteLine(table.Constraints[i].ConstraintName);
        Console.WriteLine(table.Constraints[i].GetType());
    }
}
Private Sub GetConstraint(table As DataTable)
    Dim i As Integer
    For i = 0 To table.Constraints.Count - 1
        Console.WriteLine(table.Constraints(i).ConstraintName)
        Console.WriteLine(table.Constraints(i).GetType())
    Next i
 End Sub

注解

Contains使用 方法测试是否存在特定约束。

另请参阅

适用于

Item[String]

Source:
ConstraintCollection.cs
Source:
ConstraintCollection.cs
Source:
ConstraintCollection.cs

从具有指定名称的集合中获取 Constraint

public:
 property System::Data::Constraint ^ default[System::String ^] { System::Data::Constraint ^ get(System::String ^ name); };
public:
 virtual property System::Data::Constraint ^ default[System::String ^] { System::Data::Constraint ^ get(System::String ^ name); };
public System.Data.Constraint? this[string? name] { get; }
public System.Data.Constraint this[string name] { get; }
public virtual System.Data.Constraint this[string name] { get; }
member this.Item(string) : System.Data.Constraint
Default Public ReadOnly Property Item(name As String) As Constraint
Default Public Overridable ReadOnly Property Item(name As String) As Constraint

参数

name
String

要返回的约束的 ConstraintName

属性值

具有指定名称的 Constraint;否则,如果 Constraint 不存在,则为空值。

示例

以下示例获取名为 的 Constraint

private void GetConstraint(DataTable table)
{
    if(table.Constraints.Contains("CustomersOrdersConstraint"))
    {
        Constraint constraint =
            table.Constraints["CustomersOrdersConstraint"];
    }
}
Private Sub GetConstraint(table As DataTable)
    If table.Constraints.Contains("CustomersOrdersConstraint") Then
        Dim constraint As Constraint = _
            table.Constraints("CustomersOrdersConstraint")
    End If
End Sub

注解

Contains使用 方法测试是否存在特定约束。

适用于