Stack: first warehouse, first warehouse, then warehouse, and then warehouse.
Set> stack> Create Stack
Code Using system;
Using system. Collections. Generic;
Using system. text;
Using system. collections;
Namespace consoleapplication1
{
Class Program
{
Static void main (string [] ARGs)
{
// Use the default capacity
Stack sack = new stack ();
// Use the collection element in the string array to initialize the stack object
Stack sack1 = new stack (New String [5] {"Stack element 1", "Stack element 2", "Stack element 3", "Stack element 4 ", "Stack element 5 "});
// Create a stack object and specify 20 Elements
Stack sack2 = new stack (20 );
}
}
}
Set> stack> the inbound and outbound stacks of Elements
Code Using system;
Using system. Collections. Generic;
Using system. text;
Using system. collections;
Namespace consoleapplication1
{
Class Program
{
Static void main (string [] ARGs)
{
Stack Sk = new stack ();
SK. Push ("Stack element 1"); // push method to implement element inbound Stack
SK. Push ("Stack element 2 ");
SK. Push ("Stack element 3 ");
SK. Push ("Stack element 4 ");
Displayresult (SK );
Console. writeline ("the element at the top of the stack is :");
Console. writeline (SK. Peek (); // The peek method is used to obtain the top Element Object. This method does not remove the top element.
Console. writeline ("Remove the top element: {0}", SK. Pop (); // The pop method implements the element exit stack.
Console. writeline ("the elements in the current stack are :");
Displayresult (SK );
Console. Readline ();
}
Static void displayresult (stack SK)
{
Foreach (Object s in SK)
{
Console. writeline (s );
}
}
}
}