Stack Stack Stack Stack Constructors

Definition

Overloads

Stack() Stack() Stack()

Initializes a new instance of the Stack class that is empty and has the default initial capacity.

Stack(ICollection) Stack(ICollection) Stack(ICollection) Stack(ICollection)

Initializes a new instance of the Stack class that contains elements copied from the specified collection and has the same initial capacity as the number of elements copied.

Stack(Int32) Stack(Int32) Stack(Int32) Stack(Int32)

Initializes a new instance of the Stack class that is empty and has the specified initial capacity or the default initial capacity, whichever is greater.

Stack() Stack() Stack()

Initializes a new instance of the Stack class that is empty and has the default initial capacity.

public:
 Stack();
public Stack ();
Public Sub New ()

Remarks

The capacity of a Stack is the number of elements that the Stack can hold. As elements are added to a Stack, the capacity is automatically increased as required by reallocating the internal array.

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 Stack.

This constructor is an O(1) operation.

Stack(ICollection) Stack(ICollection) Stack(ICollection) Stack(ICollection)

Initializes a new instance of the Stack class that contains elements copied from the specified collection and has the same initial capacity as the number of elements copied.

public:
 Stack(System::Collections::ICollection ^ col);
public Stack (System.Collections.ICollection col);
new System.Collections.Stack : System.Collections.ICollection -> System.Collections.Stack
Public Sub New (col As ICollection)

Parameters

col
ICollection ICollection ICollection ICollection

The ICollection to copy elements from.

Exceptions

Remarks

The capacity of a Stack is the number of elements that the Stack can hold. As elements are added to a Stack, the capacity is automatically increased as required by reallocating the internal array.

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 Stack.

The elements are copied onto the Stack in the same order they are read by the IEnumerator of the ICollection.

This constructor is an O(n) operation, where n is the number of elements in col.

See also

Stack(Int32) Stack(Int32) Stack(Int32) Stack(Int32)

Initializes a new instance of the Stack class that is empty and has the specified initial capacity or the default initial capacity, whichever is greater.

public:
 Stack(int initialCapacity);
public Stack (int initialCapacity);
new System.Collections.Stack : int -> System.Collections.Stack
Public Sub New (initialCapacity As Integer)

Parameters

initialCapacity
Int32 Int32 Int32 Int32

The initial number of elements that the Stack can contain.

Exceptions

Remarks

The capacity of a Stack is the number of elements that the Stack can hold. As elements are added to a Stack, the capacity is automatically increased as required by reallocating the internal array.

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 Stack.

This constructor is an O(n) operation, where n is initialCapacity.

Applies to