DataColumnCollection.IndexOf Method

Definition

Searches for the specified DataColumn and returns the zero-based index of the first occurrence within the collection.

Overloads

IndexOf(DataColumn)

Gets the index of a column specified by name.

IndexOf(String)

Gets the index of the column with the specific name (the name is not case sensitive).

IndexOf(DataColumn)

Gets the index of a column specified by name.

public:
 int IndexOf(System::Data::DataColumn ^ column);
public:
 virtual int IndexOf(System::Data::DataColumn ^ column);
public int IndexOf (System.Data.DataColumn? column);
public int IndexOf (System.Data.DataColumn column);
public virtual int IndexOf (System.Data.DataColumn column);
member this.IndexOf : System.Data.DataColumn -> int
abstract member IndexOf : System.Data.DataColumn -> int
override this.IndexOf : System.Data.DataColumn -> int
Public Function IndexOf (column As DataColumn) As Integer
Public Overridable Function IndexOf (column As DataColumn) As Integer

Parameters

column
DataColumn

The name of the column to return.

Returns

Int32

The index of the column specified by column if it is found; otherwise, -1.

Examples

The following example uses the Contains method to determine whether a specified column exists in a DataColumnCollection. If so, the IndexOf method returns the index of the column.

private void GetIndex(DataTable table)
{
    DataColumnCollection columns = table.Columns;
    if(columns.Contains("City"))
    {
        Console.WriteLine(columns.IndexOf("City"));
    }
}
Private Sub GetIndex(ByVal table As DataTable)
    Dim iCol As Integer
    Dim columns As DataColumnCollection = table.Columns
    If columns.Contains("City") Then
       Console.WriteLine(columns.IndexOf("City"))
    End If
End Sub

Remarks

The IndexOf method is not case-sensitive.

Applies to

IndexOf(String)

Gets the index of the column with the specific name (the name is not case sensitive).

public:
 int IndexOf(System::String ^ columnName);
public int IndexOf (string? columnName);
public int IndexOf (string columnName);
member this.IndexOf : string -> int
Public Function IndexOf (columnName As String) As Integer

Parameters

columnName
String

The name of the column to find.

Returns

Int32

The zero-based index of the column with the specified name, or -1 if the column does not exist in the collection.

Applies to