DataRowCollection.Item[Int32] 屬性

定義

取得在指定索引處的資料列。Gets the row at the specified index.

public:
 property System::Data::DataRow ^ default[int] { System::Data::DataRow ^ get(int index); };
public System.Data.DataRow this[int index] { get; }
member this.Item(int) : System.Data.DataRow
Default Public ReadOnly Property Item(index As Integer) As DataRow

參數

index
Int32

要傳回之資料列的以零起始的索引。The zero-based index of the row to return.

屬性值

DataRow

指定的 DataRowThe specified DataRow.

例外狀況

索引值大於集合中項目的數目。The index value is greater than the number of items in the collection.

範例

下列範例會列印中每個資料列的資料行1值 DataRowCollectionThe following example prints the value of column 1 of each row in a DataRowCollection.

private void PrintRows(DataTable table)
{
    // Print the CompanyName column for every row using the index.
    for(int i = 0; i < table.Rows.Count; i++)
    {
        Console.WriteLine(table.Rows[i]["CompanyName"]);
    }
}
Private Sub PrintRows(table As DataTable)
     ' Print the first column for every row using the index.
     Dim i As Integer
     For i = 0 To table.Rows.Count - 1
         Console.WriteLine(table.Rows(i)(0))
     Next i
End Sub

備註

Contains 可以使用方法來判斷資料列的索引鍵資料行中是否有特定的值。Use the Contains method to determine whether a specific value exists in the key column of a row.

適用於

另請參閱