共用方式為


ConstraintCollection.Item[] 屬性

定義

從集合中取得指定的 Constraint

多載

Item[Int32]

從集合的指定索引處取得 Constraint

Item[String]

以指定名稱從集合取得 Constraint

Item[Int32]

來源:
ConstraintCollection.cs
來源:
ConstraintCollection.cs
來源:
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]

來源:
ConstraintCollection.cs
來源:
ConstraintCollection.cs
來源:
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,否則為 Null 值 (如果 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使用方法來測試特定條件約束是否存在。

適用於