DataColumnCollection 类

定义

表示 DataColumnDataTable 对象的集合。Represents a collection of DataColumn objects for a DataTable.

public ref class DataColumnCollection sealed : System::Data::InternalDataCollectionBase
[System.Serializable]
public sealed class DataColumnCollection : System.Data.InternalDataCollectionBase
type DataColumnCollection = class
    inherit InternalDataCollectionBase
Public NotInheritable Class DataColumnCollection
Inherits InternalDataCollectionBase
继承
DataColumnCollection
属性

示例

下面的示例循环访问DataColumn对象的集合,并输出集合中每个列的各种属性。The following example iterates through a collection of DataColumn objects and prints various properties of each column in the collection.

private void PrintDataTableColumnInfo(DataTable table)
{
    // Use a DataTable object's DataColumnCollection.
    DataColumnCollection columns = table.Columns;

    // Print the ColumnName and DataType for each column.
    foreach(DataColumn column in columns)
    {
        Console.WriteLine(column.ColumnName);
        Console.WriteLine(column.DataType);
    }
}
Private Sub PrintDataTableColumnInfo(table As DataTable)
    
    ' Use a DataTable object's DataColumnCollection.
    Dim columns As DataColumnCollection = table.Columns

    ' Print the ColumnName and DataType for each column.
    Dim column As DataColumn
    For Each column in columns
       Console.WriteLine(column.ColumnName)
       Console.WriteLine(column.DataType.ToString)
    Next
End Sub

注解

定义的架构DataTable,并确定每个DataColumn可包含的数据类型。 DataColumnCollectionThe DataColumnCollection defines the schema of a DataTable, and determines what kind of data each DataColumn can contain. 可以DataColumnCollection DataTable通过对象的属性访问。 ColumnsYou can access the DataColumnCollection through the Columns property of the DataTable object.

使用和DataColumn方法来插入和删除对象。 Remove Add DataColumnCollectionThe DataColumnCollection uses the Add and Remove methods to insert and delete DataColumn objects. 使用属性可确定集合中有DataColumn多少个对象。 CountUse the Count property to determine how many DataColumn objects are in the collection. Contains使用方法验证集合中是否存在指定的索引或列名称。Use the Contains method to verify whether a specified index or column name exists in the collection.

属性

Count

获取集合中的元素总数。Gets the total number of elements in a collection.

(继承自 InternalDataCollectionBase)
IsReadOnly

获取一个值,该值指示 InternalDataCollectionBase 是否为只读。Gets a value that indicates whether the InternalDataCollectionBase is read-only.

(继承自 InternalDataCollectionBase)
IsSynchronized

获取一个值,该值指示 InternalDataCollectionBase 是否已同步。Gets a value that indicates whether the InternalDataCollectionBase is synchronized.

(继承自 InternalDataCollectionBase)
Item[Int32]

从集合中获取位于指定索引位置的 DataColumnGets the DataColumn from the collection at the specified index.

Item[String]

从具有指定名称的集合中获取 DataColumnGets the DataColumn from the collection with the specified name.

List

获取作为列表的集合的项。Gets the items of the collection as a list.

(继承自 InternalDataCollectionBase)
SyncRoot

获取可用于同步集合的对象。Gets an object that can be used to synchronize the collection.

(继承自 InternalDataCollectionBase)

方法

Add()

创建 DataColumn 对象并将其添加到 DataColumnCollection 中。Creates and adds a DataColumn object to the DataColumnCollection.

Add(DataColumn)

创建指定的 DataColumn 对象并将其添加到 DataColumnCollectionCreates and adds the specified DataColumn object to the DataColumnCollection.

Add(String)

创建一个具有指定名称的 DataColumn 对象,并将其添加到 DataColumnCollection 中。Creates and adds a DataColumn object that has the specified name to the DataColumnCollection.

Add(String, Type)

创建一个具有指定名称和类型的 DataColumn 对象,并将其添加到 DataColumnCollection 中。Creates and adds a DataColumn object that has the specified name and type to the DataColumnCollection.

Add(String, Type, String)

创建一个具有指定名称、类型和表达式的 DataColumn 对象,并将其添加到 DataColumnCollection 中。Creates and adds a DataColumn object that has the specified name, type, and expression to the DataColumnCollection.

AddRange(DataColumn[])

将指定的 DataColumn 数组的元素复制到集合末尾。Copies the elements of the specified DataColumn array to the end of the collection.

CanRemove(DataColumn)

检查是否可从集合中移除特定列。Checks whether a specific column can be removed from the collection.

Clear()

清除集合中的所有列。Clears the collection of any columns.

Contains(String)

检查集合是否包含具有指定名称的列。Checks whether the collection contains a column with the specified name.

CopyTo(Array, Int32)

将当前 InternalDataCollectionBase 的所有元素复制到一维 Array,从指定的 InternalDataCollectionBase 索引开始。Copies all the elements of the current InternalDataCollectionBase to a one-dimensional Array, starting at the specified InternalDataCollectionBase index.

(继承自 InternalDataCollectionBase)
CopyTo(DataColumn[], Int32)

将整个集合复制到现有数组中,从该数组内的指定索引处开始复制。Copies the entire collection into an existing array, starting at a specified index within the array.

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetEnumerator()

获取集合的 IEnumeratorGets an IEnumerator for the collection.

(继承自 InternalDataCollectionBase)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
IndexOf(DataColumn)

获取按名称指定的列的索引。Gets the index of a column specified by name.

IndexOf(String)

获取具有特定名称的列的索引(名称不区分大小写)。Gets the index of the column with the specific name (the name is not case sensitive).

MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
Remove(DataColumn)

从集合中移除指定的 DataColumn 对象。Removes the specified DataColumn object from the collection.

Remove(String)

从集合中移除具有指定名称的 DataColumn 对象。Removes the DataColumn object that has the specified name from the collection.

RemoveAt(Int32)

从集合中移除指定索引位置的列。Removes the column at the specified index from the collection.

ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

事件

CollectionChanged

在由于添加或删除列而使列集合发生变化时发生。Occurs when the columns collection changes, either by adding or removing a column.

扩展方法

Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

启用查询的并行化。Enables parallelization of a query.

AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

适用于

线程安全性

对于多线程读取操作,此类型是安全的。This type is safe for multithreaded read operations. 必须同步任何写入操作。You must synchronize any write operations.

另请参阅