System.Collections.Generic.Stack
Added in .NET 2.0
A stack represents a last in, first out collection (LIFO)
The principle methods for adding to and removing from are the Push and Pop methods
generic stack of objects
a list in first out structure
Methods
Clear | Removes all objects |
Contains | Determines if an element exists |
CopyTo | Copies the stack elements to an existing one-dimensional array |
Count | |
GetEnumerator | |
Peek | Returns the object at the top of the stack without removing it |
Pop | Removes the object at the top of the stack |
Push | Inserts an object at the top of the stack |
ToArray | Copies the stack elements to a new one dimensional array |
private class BET_GenericStack : System.Collections.Generic.Stack
{
}
int mysize = 10;
int myvalue;
int mytotal;
BET_GenericStack<double> myStack;
myStack = new BET_GenericStack<double>(mysize);
for (int i=0; I < mysize; i++)
{
myStack.Push(i);
System.Console.Writeline("Pushed - " + i);
}
for (int i=0; I < mysize; i++)
{
myvalue = myStack.Pop();
mytotal += myvalue;
System.Console.Writeline("Popped - " + myvalue);
}
System.Console.WriteLine("Total - " + mytotal);
Non Generic
This class is not to be confused with the Non Generic Stack class that was introduced in .NET 1.1
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext