CollectionBase Constructors

Definition

初始化 CollectionBase 类的新实例。Initializes a new instance of the CollectionBase class.

Overloads

CollectionBase()

使用默认初始容量初始化 CollectionBase 类的新实例。Initializes a new instance of the CollectionBase class with the default initial capacity.

CollectionBase(Int32)

使用指定容量初始化 CollectionBase 类的新实例。Initializes a new instance of the CollectionBase class with the specified capacity.

CollectionBase()

使用默认初始容量初始化 CollectionBase 类的新实例。Initializes a new instance of the CollectionBase class with the default initial capacity.

protected:
 CollectionBase();
protected CollectionBase ();
Protected Sub New ()

Remarks

CollectionBase 的容量是 CollectionBase 可以容纳的元素数。The capacity of a CollectionBase is the number of elements that the CollectionBase can hold. 将元素添加到 CollectionBase时,将根据需要通过重新分配内部数组来自动增加容量。As elements are added to a CollectionBase, the capacity is automatically increased as required by reallocating the internal array.

如果集合的大小可为估算值,则指定初始容量就无需在将元素添加到 CollectionBase时执行多个大小调整操作。If the size of the collection can be estimated, specifying the initial capacity eliminates the need to perform a number of resizing operations while adding elements to the CollectionBase.

此构造函数是一个 O(1) 操作。This constructor is an O(1) operation.

See also

CollectionBase(Int32)

使用指定容量初始化 CollectionBase 类的新实例。Initializes a new instance of the CollectionBase class with the specified capacity.

protected:
 CollectionBase(int capacity);
protected CollectionBase (int capacity);
new System.Collections.CollectionBase : int -> System.Collections.CollectionBase
Protected Sub New (capacity As Integer)

Parameters

capacity
Int32

新列表最初可以存储的元素数。The number of elements that the new list can initially store.

Remarks

CollectionBase 的容量是 CollectionBase 可以容纳的元素数。The capacity of a CollectionBase is the number of elements that the CollectionBase can hold. 将元素添加到 CollectionBase时,将根据需要通过重新分配内部数组来自动增加容量。As elements are added to a CollectionBase, the capacity is automatically increased as required by reallocating the internal array.

如果集合的大小可为估算值,则指定初始容量就无需在将元素添加到 CollectionBase时执行多个大小调整操作。If the size of the collection can be estimated, specifying the initial capacity eliminates the need to perform a number of resizing operations while adding elements to the CollectionBase.

此构造函数是 O(n) 操作,其中 ncapacity的。This constructor is an O(n) operation, where n is capacity.

See also

Applies to