C # Stack set of learning

Stack set of learning

Learning From: blog Garden Related Articles

Stack<T>set

This feature set is: LIFO, is simply the new elements on the first place, but also the order of the elements is removed from the first beginning.

Method a: Push(T value);adding an element to the set top position.
Method Two: Pop();Adding an element to the set top position.
Method three: Peek();adding an element to the set top position.

Stack<string> sTest=new Stack<string>();
sTest.Push("D");
sTest.Push("A");
sTest.Push("B");
sTest.Push("A");
sTest.Push("C");

For this operation, List<T>the output result is: DABAC. But our Stack<T>result set output is:. CABAD
each new element is added are placed in front of the collection.

String JustPop = sTest.Pop();
Console.WriteLine("我是被移除的那个元素:"+JustPop);

So we output the results as follows:

I'm the one element is removed: C

Here we can see that we use the .Pop();method to remove all elements of our current Stack<T>that last set of elements added, is that element is first output.

Guess you like

Origin www.cnblogs.com/cao-1/p/12075793.html