Stack
CollectionThe System.Collections.Stack
collection mimics the same-named memory area and works according to the LIFO (Last-In, First-Out) paradigm meaning that the last item you add to the collection is the first that is pulled out from the collection. Stack
exposes three important methods: Push
that adds an item to the collection, Pop
that allows consuming and removing an item from the collection, and Peek
that returns the top item in the collection without removing it. The following is an example:
As for Queue
, here you work with Object
items. Although this enables pushing different kinds of objects to the collection, it is not a good idea. You should prefer the generic counterpart (Stack(Of T)
) that enables working with a single type in a strongly typed fashion. The Stack
collection also exposes the Count
property which returns the number of objects that it stores.
3.133.93.30