C # stack of collection,
Stack is a very similar container to queue, But Stack is a post-in-first-out (LIFO) container.
The stack uses the Push () method to add elements to the stack, and uses the Pop () method to obtain the most recently added element:
Similar to the Queue <T> class (http://www.cnblogs.com/afei-24/p/6829817.html), Stack implements the ICollection and IEnumerable <T> interfaces.
Stack <T> class member:
In a foreach statement, the stack enumerator does not delete elements, but returns elements one by one. Using the Pop () method, each element is read from the stack and deleted.
Static void Main () {var alphabet = new Stack <char> (); alphabet. push ('A'); alphabet. push ('B'); alphabet. push ('C'); Console. write ("First iteration:"); foreach (char item in alphabet) {Console. write (item);} Console. writeLine (); Console. write ("Second iteration:"); while (alphabet. count> 0) {Console. write (alphabet. pop ();} Console. writeLine ();}
The stack becomes empty after the second iteration.