DataColumnCollection DataColumnCollection DataColumnCollection DataColumnCollection Class

定義

表示 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
繼承
屬性

範例

下列範例會逐一查看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物件的Columns屬性存取。You can access the DataColumnCollection through the Columns property of the DataTable object.

DataColumnCollection DataColumn使用和方法Remove來插入和刪除物件。 AddThe 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 Count Count Count

取得集合中的項目總數。Gets the total number of elements in a collection.

(Inherited from InternalDataCollectionBase)
IsReadOnly IsReadOnly IsReadOnly IsReadOnly

取得值,這個值表示 InternalDataCollectionBase 是否為唯讀。Gets a value that indicates whether the InternalDataCollectionBase is read-only.

(Inherited from InternalDataCollectionBase)
IsSynchronized IsSynchronized IsSynchronized IsSynchronized

取得值,表示 InternalDataCollectionBase 是否同步處理。Gets a value that indicates whether the InternalDataCollectionBase is synchronized.

(Inherited from InternalDataCollectionBase)
Item[Int32] Item[Int32] Item[Int32] Item[Int32]

從集合的指定索引處取得 DataColumnGets the DataColumn from the collection at the specified index.

Item[String] Item[String] Item[String] Item[String]

以指定名稱從集合取得 DataColumnGets the DataColumn from the collection with the specified name.

List List List List

取得集合的項目做為清單。Gets the items of the collection as a list.

(Inherited from InternalDataCollectionBase)
SyncRoot SyncRoot SyncRoot SyncRoot

取得可以用來同步集合的物件。Gets an object that can be used to synchronize the collection.

(Inherited from InternalDataCollectionBase)

方法

Add() Add() Add() Add()

建立 DataColumn 物件,並將它加入 DataColumnCollectionCreates and adds a DataColumn object to the DataColumnCollection.

Add(DataColumn) Add(DataColumn) Add(DataColumn) Add(DataColumn)

建立指定的 DataColumn 物件,並將它加入 DataColumnCollectionCreates and adds the specified DataColumn object to the DataColumnCollection.

Add(String) Add(String) Add(String) Add(String)

建立具有指定名稱的 DataColumn 物件,並將它加入 DataColumnCollectionCreates and adds a DataColumn object that has the specified name to the DataColumnCollection.

Add(String, Type) Add(String, Type) Add(String, Type) Add(String, Type)

建立具有指定名稱和型別的 DataColumn 物件,並將它加入 DataColumnCollectionCreates and adds a DataColumn object that has the specified name and type to the DataColumnCollection.

Add(String, Type, String) Add(String, Type, String) Add(String, Type, String) Add(String, Type, String)

建立具有指定名稱、型別和運算式的 DataColumn 物件,並將它加入 DataColumnCollectionCreates and adds a DataColumn object that has the specified name, type, and expression to the DataColumnCollection.

AddRange(DataColumn[]) AddRange(DataColumn[]) AddRange(DataColumn[]) AddRange(DataColumn[])

將指定的 DataColumn 陣列元素複製到集合的末端。Copies the elements of the specified DataColumn array to the end of the collection.

CanRemove(DataColumn) CanRemove(DataColumn) CanRemove(DataColumn) CanRemove(DataColumn)

檢查是否可以從集合移除特定的資料行。Checks whether a specific column can be removed from the collection.

Clear() Clear() Clear() Clear()

清除任何資料行的集合。Clears the collection of any columns.

Contains(String) Contains(String) Contains(String) Contains(String)

檢查集合是否包含具有指定名稱的資料行。Checks whether the collection contains a column with the specified name.

CopyTo(Array, Int32) CopyTo(Array, Int32) CopyTo(Array, Int32) 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.

(Inherited from InternalDataCollectionBase)
CopyTo(DataColumn[], Int32) CopyTo(DataColumn[], Int32) CopyTo(DataColumn[], Int32) CopyTo(DataColumn[], Int32)

將整個集合複製到現有陣列中,並於陣列中指定的索引處開始寫入。Copies the entire collection into an existing array, starting at a specified index within the array.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

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

(Inherited from InternalDataCollectionBase)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
IndexOf(DataColumn) IndexOf(DataColumn) IndexOf(DataColumn) IndexOf(DataColumn)

取得由名稱指定的資料行索引。Gets the index of a column specified by name.

IndexOf(String) IndexOf(String) IndexOf(String) IndexOf(String)

取得具有特定名稱 (名稱不區分大小寫) 的資料行索引。Gets the index of the column with the specific name (the name is not case sensitive).

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
Remove(DataColumn) Remove(DataColumn) Remove(DataColumn) Remove(DataColumn)

從集合中移除指定的 DataColumn 物件。Removes the specified DataColumn object from the collection.

Remove(String) Remove(String) Remove(String) Remove(String)

從集合移除具有指定名稱的 DataColumn 物件。Removes the DataColumn object that has the specified name from the collection.

RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32)

從集合移除在指定索引處的資料行。Removes the column at the specified index from the collection.

ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

事件

CollectionChanged CollectionChanged CollectionChanged CollectionChanged

發生於資料行集合變更時 (藉由加入或移除資料行)。Occurs when the columns collection changes, either by adding or removing a column.

擴充方法

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

IEnumerable 的項目轉換成指定的型別。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

根據指定的型別來篩選 IEnumerable 的項目。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

啟用查詢的平行化作業。Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryableConverts an IEnumerable to an IQueryable.

適用於

執行緒安全性

這種類型對於多執行緒讀取作業而言是安全的。This type is safe for multithreaded read operations. 您必須同步處理任何寫入作業。You must synchronize any write operations.

另請參閱