Прочитать на английском Изменить

Поделиться через


DataColumnMappingCollection.IndexOf Method

Definition

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Gets the location of the specified DataColumnMapping within the collection.

Overloads

IndexOf(String)

Gets the location of the DataColumnMapping with the specified source column name.

IndexOf(Object)

Gets the location of the specified Object that is a DataColumnMapping within the collection.

IndexOf(String)

Source:
DataColumnMappingCollection.cs
Source:
DataColumnMappingCollection.cs
Source:
DataColumnMappingCollection.cs

Gets the location of the DataColumnMapping with the specified source column name.

public int IndexOf(string? sourceColumn);
public int IndexOf(string sourceColumn);

Parameters

sourceColumn
String

The case-sensitive name of the source column.

Returns

The zero-based location of the DataColumnMapping with the specified case-sensitive source column name.

Implements

Examples

The following example searches for a DataColumnMapping object with the given source column name within a DataColumnMappingCollection collection. If the DataColumnMapping 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 DataColumnMappingCollection collection has been created.

public void FindDataColumnMapping()
{
    // ...
    // create columnMappings
    // ...
    if (!columnMappings.Contains("Description"))
    {
        Console.WriteLine("Error: no such table in collection.");
    }
    else
    {
        Console.WriteLine("Name {0}",
            columnMappings["Description"].ToString());
        Console.WriteLine("Index: {0}",
            columnMappings.IndexOf("Description").ToString());
    }
}

See also

Applies to

.NET 10 и другие версии
Продукт Версии
.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(Object)

Source:
DataColumnMappingCollection.cs
Source:
DataColumnMappingCollection.cs
Source:
DataColumnMappingCollection.cs

Gets the location of the specified Object that is a DataColumnMapping within the collection.

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

Parameters

value
Object

An Object that is the DataColumnMapping to find.

Returns

The zero-based location of the specified Object that is a DataColumnMapping within the collection.

Implements

Examples

The following example searches for a DataColumnMapping 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 DataColumnMappingCollection collection and a DataColumnMapping object have been created.

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

See also

Applies to

.NET 10 и другие версии
Продукт Версии
.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