Represents a simple last-in-first-out (LIFO) non-generic collection of objects.
Assembly: mscorlib (in mscorlib.dll)
Thetype exposes the following members.
|Stack()||Initializes a new instance of the class that is empty and has the default initial capacity.|
|Stack(ICollection)||Initializes a new instance of the 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 class that is empty and has the specified initial capacity or the default initial capacity, whichever is greater.|
|Clear||Removes all objects from the .|
|Clone||Creates a shallow copy of the .|
|Contains||Determines whether an element is in the .|
|CopyTo||Copies the to an existing one-dimensional Array, starting at the specified array index.|
|Equals(Object)||Determines whether the specified object is equal to the current object. (Inherited from Object.)|
|Finalize||Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)|
|GetEnumerator||Returns an IEnumerator for the .|
|GetHashCode||Serves as the default hash function. (Inherited from Object.)|
|GetType||Gets the Type of the current instance. (Inherited from Object.)|
|MemberwiseClone||Creates a shallow copy of the current Object. (Inherited from Object.)|
|Peek||Returns the object at the top of the without removing it.|
|Pop||Removes and returns the object at the top of the .|
|Push||Inserts an object at the top of the .|
|Synchronized||Returns a synchronized (thread safe) wrapper for the .|
|ToArray||Copies the to a new array.|
|ToString||Returns a string that represents the current object. (Inherited from Object.)|
|AsParallel()||Overloaded. Enables parallelization of a query. (Defined by ParallelEnumerable.)|
|AsParallel()||Overloaded. (Defined by ParallelEnumerable.)|
|AsQueryable()||Overloaded. Converts an IEnumerable to an IQueryable. (Defined by Queryable.)|
|AsQueryable()||Overloaded. (Defined by Queryable.)|
|Cast(TResult)()||Overloaded. Casts the elements of an IEnumerable to the specified type. (Defined by Enumerable.)|
|Cast(TResult)()||Overloaded. (Defined by Enumerable.)|
|OfType(TResult)()||Overloaded. Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.)|
|OfType(TResult)()||Overloaded. (Defined by Enumerable.)|
For the generic version of this collection, see System.Collections.Generic.Stack(T).
is implemented as a circular buffer.
The capacity of a is the number of elements the can hold. As elements are added to a , the capacity is automatically increased as required through reallocation.
If Count is less than the capacity of the stack, Push is an O(1) operation. If the capacity needs to be increased to accommodate the new element, Push becomes an O(n) operation, where n is Count. Pop is an O(1) operation.
accepts a null reference (Nothing in Visual Basic) as a valid value and allows duplicate elements.
Public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
To guarantee the thread safety of the , all operations must be done through the wrapper returned by the Synchronized method.
Enumerating through a collection is intrinsically not a thread-safe procedure. Even when a collection is synchronized, other threads can still modify the collection, which causes the enumerator to throw an exception. To guarantee thread safety during enumeration, you can either lock the collection during the entire enumeration or catch the exceptions resulting from changes made by other threads.