ConstraintCollection.Item[] Property

Definition

Gets the specified Constraint from the collection.

Overloads

Item[Int32]

Gets the Constraint from the collection at the specified index.

Item[String]

Gets the Constraint from the collection with the specified name.

Item[Int32]

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

Gets the Constraint from the collection at the specified index.

public System.Data.Constraint this[int index] { get; }
public virtual System.Data.Constraint this[int index] { get; }

Parameters

index
Int32

The index of the constraint to return.

Property Value

The Constraint at the specified index.

Exceptions

The index value is greater than the number of items in the collection.

Examples

The following example gets each Constraint from the ConstraintCollection.

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());
    }
}

Remarks

Use the Contains method to test for the existence of a specific constraint.

See also

Applies to

.NET 9 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

Item[String]

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

Gets the Constraint from the collection with the specified 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; }

Parameters

name
String

The ConstraintName of the constraint to return.

Property Value

The Constraint with the specified name; otherwise a null value if the Constraint does not exist.

Examples

The following example gets the named Constraint.

private void GetConstraint(DataTable table)
{
    if(table.Constraints.Contains("CustomersOrdersConstraint"))
    {
        Constraint constraint =
            table.Constraints["CustomersOrdersConstraint"];
    }
}

Remarks

Use the Contains method to test for the existence of a specific constraint.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1