DataColumnMappingCollection.IndexOf 方法

定義

取得集合中指定的 DataColumnMapping 位置。

多載

IndexOf(String)

取得具有指定來源資料行名稱的 DataColumnMapping 位置。

IndexOf(Object)

取得在集合中為 Object 的指定 DataColumnMapping 位置。

IndexOf(String)

來源:
DataColumnMappingCollection.cs
來源:
DataColumnMappingCollection.cs
來源:
DataColumnMappingCollection.cs

取得具有指定來源資料行名稱的 DataColumnMapping 位置。

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

參數

sourceColumn
String

來源資料行的區分大小寫名稱。

傳回

具有指定區分大小寫來源資料行名稱的 DataColumnMapping 之以零起始的位置。

實作

範例

下列範例會搜尋 DataColumnMapping 集合中 DataColumnMappingCollection 具有指定源數據行名稱的物件。 DataColumnMapping如果 存在,此範例會顯示對應的名稱和索引。 如果對應不存在,此範例會顯示錯誤。 此範例假設 DataColumnMappingCollection 已建立集合。

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());
    }
}
Public Sub FindDataColumnMapping()
    ' ...
    ' create columnMappings
    ' ...
    If Not columnMappings.Contains("Description") Then
        Console.WriteLine("Error: no such table in collection.")
    Else
       Console.WriteLine("Name: {0}", _
           columnMappings("Description").ToString())
       Console.WriteLine("Index: {0}", _
           columnMappings.IndexOf("Description").ToString())
    End If
End Sub

另請參閱

適用於

IndexOf(Object)

來源:
DataColumnMappingCollection.cs
來源:
DataColumnMappingCollection.cs
來源:
DataColumnMappingCollection.cs

取得在集合中為 Object 的指定 DataColumnMapping 位置。

public:
 virtual int IndexOf(System::Object ^ value);
public int IndexOf (object? value);
public int IndexOf (object value);
abstract member IndexOf : obj -> int
override this.IndexOf : obj -> int
Public Function IndexOf (value As Object) As Integer

參數

value
Object

Object,即是要尋找的 DataColumnMapping

傳回

在集合中為 Object 的指定 DataColumnMapping 之以零起始位置。

實作

範例

下列範例會在 集合內搜尋 DataColumnMapping 。 如果對應存在於集合中,則會移除它。 如果集合內沒有對應,則會將其新增至集合,並顯示其索引。 此範例假設 DataColumnMappingCollection 已建立集合和 DataColumnMapping 物件。

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));
    }
}
Public Sub ChangedMyMind()
    ' ...
    ' create mappings and mapping
    ' ...
    If mappings.Contains(CType(mapping, Object)) Then
        mappings.Remove(CType(mapping, Object))
    Else
        mappings.Add(CType(mapping, Object))
        Console.WriteLine("Index of new mapping: " & _
           mappings.IndexOf(CType(mapping, Object)).ToString())
    End If
End Sub

另請參閱

適用於