Bewerken

Share via


Stack Constructors

Definition

Initializes a new instance of the Stack class.

Overloads

Stack()

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

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)

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()

Source:
Stack.cs
Source:
Stack.cs
Source:
Stack.cs

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.

Applies to

Stack(ICollection)

Source:
Stack.cs
Source:
Stack.cs
Source:
Stack.cs

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

The ICollection to copy elements from.

Exceptions

col is null.

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

Applies to

Stack(Int32)

Source:
Stack.cs
Source:
Stack.cs
Source:
Stack.cs

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

The initial number of elements that the Stack can contain.

Exceptions

initialCapacity is less than zero.

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