Compartilhar via


Stack Collection Types 

The Stack class and the Stack generic class are last-in-first-out collection classes that implement the ICollection interface. The Stack generic class also implements the ICollection generic interface.

Stacks and queues are useful when you need temporary storage for information, that is, when you might want to discard an element after retrieving its value. Use Queue if you need to access the information in the same order that it is stored in the collection. Use Stack if you need to access the information in reverse order.

A common use for a Stack is preserving variable states during calls to other procedures.

Three main operations can be performed on a Stack and its elements:

  • Push inserts an element at the top of the Stack.

  • Pop removes an element at the top of the Stack.

  • Peek returns an element at the top of the Stack but does not remove it from the Stack.

See Also

Reference

Stack
System.Collections.Generic.Stack
Queue
System.Collections.Generic.Queue
ICollection
System.Collections.Generic.ICollection

Other Resources

Commonly Used Collection Types