DataColumnCollection.Item[] 属性
定义
从集合中获取指定的 DataColumn。Gets the specified DataColumn from the collection.
重载
| Item[Int32] |
从集合中获取位于指定索引位置的 DataColumn。Gets the DataColumn from the collection at the specified index. |
| Item[String] |
从具有指定名称的集合中获取 DataColumn。Gets the DataColumn from the collection with the specified name. |
Item[Int32]
从集合中获取位于指定索引位置的 DataColumn。Gets the DataColumn from the collection at the specified index.
public:
property System::Data::DataColumn ^ default[int] { System::Data::DataColumn ^ get(int index); };
public:
virtual property System::Data::DataColumn ^ default[int] { System::Data::DataColumn ^ get(int index); };
public System.Data.DataColumn this[int index] { get; }
public virtual System.Data.DataColumn this[int index] { get; }
member this.Item(int) : System.Data.DataColumn
Default Public ReadOnly Property Item(index As Integer) As DataColumn
Default Public Overridable ReadOnly Property Item(index As Integer) As DataColumn
参数
- index
- Int32
要返回的列的从零开始的索引。The zero-based index of the column to return.
属性值
指定索引处的 DataColumn。The DataColumn at the specified index.
例外
索引值大于集合中的项目数。The index value is greater than the number of items in the collection.
示例
下面的示例使用 Item[] 属性打印 ColumnName 索引指定的对象的值 DataColumn 。The following example uses the Item[] property to print the ColumnName value of a DataColumn object specified by index. 该示例使用了 DataTable system.web 控件中包含的。The example uses the DataTable that is contained by a System.Windows.Forms.DataGrid control.
private void PrintColumnNamesByIndex(DataTable table)
{
// Get the DataColumnCollection from a DataTable in a DataSet.
DataColumnCollection columns = table.Columns;
// Print each column's name using the Index.
for (int i = 0 ;i <columns.Count ;i++)
Console.WriteLine(columns[i]);
}
Private Sub PrintColumnNamesByIndex(table As DataTable)
' Get the DataColumnCollection from a DataTable in a DataSet.
Dim columns As DataColumnCollection = table.Columns
' Print each column's name using the Index.
Dim i As Integer
For i = 0 To columns.Count - 1
Console.WriteLine(columns(i))
Next i
End Sub
注解
Contains方法可用于测试列是否存在。The Contains method can be used to test for the existence of a column. 在尝试使用之前,此方法非常有用 Item[] 。This is useful before you try to use Item[].
另请参阅
适用于
Item[String]
从具有指定名称的集合中获取 DataColumn。Gets the DataColumn from the collection with the specified name.
public:
property System::Data::DataColumn ^ default[System::String ^] { System::Data::DataColumn ^ get(System::String ^ name); };
public:
virtual property System::Data::DataColumn ^ default[System::String ^] { System::Data::DataColumn ^ get(System::String ^ name); };
public System.Data.DataColumn? this[string name] { get; }
public System.Data.DataColumn this[string name] { get; }
public virtual System.Data.DataColumn this[string name] { get; }
member this.Item(string) : System.Data.DataColumn
Default Public ReadOnly Property Item(name As String) As DataColumn
Default Public Overridable ReadOnly Property Item(name As String) As DataColumn
参数
- name
- String
要返回的列的 ColumnName。The ColumnName of the column to return.
属性值
具有指定 DataColumn 的集合中的 ColumnName,否则,如果 DataColumn 不存在,则为空值。The DataColumn in the collection with the specified ColumnName; otherwise a null value if the DataColumn does not exist.
示例
下面的示例使用 Item[] 属性打印 DataType 索引指定的对象的值 DataColumn 。The following example uses the Item[] property to print the DataType value of a DataColumn object specified by index.
private void PrintDataType(DataTable table)
{
// Get the DataColumnCollection from a DataTable in a DataSet.
DataColumnCollection columns = table.Columns;
// Print the column's data type.
Console.WriteLine(columns["id"].DataType);
}
Private Sub PrintDataType(table As DataTable)
' Get the DataColumnCollection from a DataTable in a DataSet.
Dim columns As DataColumnCollection = table.Columns
' Print the column's data type.
Console.WriteLine(columns("id").DataType)
End Sub
注解
Item[] 在搜索列名称时,是有条件区分大小写的。Item[] is conditionally case-sensitive when it searches for column names. 例如,如果一个 DataColumn 名为 "mydatacolumn",另一个名为 "mydatacolumn",则用于搜索其中一列的字符串将被视为区分大小写。For example, if one DataColumn is named "mydatacolumn" and another is named "Mydatacolumn", a string used to search for one of the columns is regarded as case-sensitive. 但是,如果 "mydatacolumn" 存在并且 "Mydatacolumn" 不是,则搜索字符串将被视为不区分大小写。However, if "mydatacolumn" exists and "Mydatacolumn" does not, the search string is regarded as case-insensitive.