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

ClearRemoves all objects
ContainsDetermines if an element exists
CopyToCopies the stack elements to an existing one-dimensional array
Count 
GetEnumerator 
PeekReturns the object at the top of the stack without removing it
PopRemoves the object at the top of the stack
PushInserts an object at the top of the stack
ToArrayCopies 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