This documentation is archived and is not being maintained.

ConstraintCollection.IndexOf Method (String)

Gets the index of the Constraint specified by name.

Namespace: System.Data
Assembly: System.Data (in system.data.dll)

public int IndexOf (
	string constraintName
)
public int IndexOf (
	String constraintName
)
public function IndexOf (
	constraintName : String
) : int

Parameters

constraintName

The name of the Constraint.

Return Value

The index of the Constraint if it is in the collection; otherwise, -1.

Use the IndexOf method to return an index to be used with either the Contains or Remove method.

The following example uses the IndexOf method to return the index of a Constraint. The index is passed to the Contains method to determine whether the collection contains the constraint, before removing it.

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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Show: