DataTableMappingCollection.IndexOf Method

Definition

Gets the location of the specified DataTableMapping object within the collection.

Overloads

IndexOf(Object)

Gets the location of the specified DataTableMapping object within the collection.

IndexOf(String)

Gets the location of the DataTableMapping object with the specified source table name.

IndexOf(Object)

Source:
DataTableMappingCollection.cs
Source:
DataTableMappingCollection.cs
Source:
DataTableMappingCollection.cs

Gets the location of the specified DataTableMapping object within the collection.

C#
public int IndexOf(object? value);
C#
public int IndexOf(object value);

Parameters

value
Object

An Object that is the DataTableMapping object to find.

Returns

The zero-based location of the specified DataTableMapping object within the collection.

Implements

Examples

The following example searches for a DataTableMapping within the collection. If the mapping exists in the collection, it is removed. If the mapping does not exist within the collection, it is added to the collection and its index is displayed. The example assumes that a DataTableMappingCollection collection and a DataTableMapping object have been created.

C#
public void ChangedMyMind()
{
    // ...
    // create mappings and mapping
    // ...
    if (mappings.Contains((Object) mapping))
    {
        mappings.Remove((Object) mapping);
    }
    else
    {
        mappings.Add((Object) mapping);
        Console.WriteLine("Index of new mapping: "
            + mappings.IndexOf((Object) mapping));
    }
}

Applies to

.NET 10 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, 10
.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

IndexOf(String)

Source:
DataTableMappingCollection.cs
Source:
DataTableMappingCollection.cs
Source:
DataTableMappingCollection.cs

Gets the location of the DataTableMapping object with the specified source table name.

C#
public int IndexOf(string? sourceTable);
C#
public int IndexOf(string sourceTable);

Parameters

sourceTable
String

The case-sensitive name of the source table.

Returns

The zero-based location of the DataTableMapping object with the specified source table name.

Implements

Examples

The following example searches for a DataTableMapping object with the given source table name within a DataTableMappingCollection collection. If the DataTableMapping exists, the example displays the name and the index of the mapping. If the mapping does not exist, the example displays an error. This example assumes that a DataTableMappingCollection collection has been created.

C#
public void FindDataTableMapping()
{
    // ...
    // create mappings
    // ...
    if (!mappings.Contains("Categories"))
        Console.WriteLine("Error: no such table in collection");
    else
        Console.WriteLine
            ("Name: " + mappings["Categories"].ToString() + "\n"
            + "Index: " + mappings.IndexOf("Categories").ToString());
}

Applies to

.NET 10 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, 10
.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