Перейти к содержимому

Part 83 Generic stack collection class

kudvenkat

0:00 / 0:00

Part 83 Generic stack collection class

88 663 просмотра · 13 лет назад
kudvenkat
845 тыс. подписчиков
88 663 просмотра · 13 лет назад
Link for code samples used in the demo http://csharp-video-tutorials.blogspo... Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.    / @aarvikitchen5572   Link for csharp, asp.net, ado.net, dotnet basics, mvc and sql server video tutorial playlists https://www.youtube.com/user/kudvenka... Slides http://csharp-video-tutorials.blogspo... Stack is a generic LIFO (Last In First Out) collection class that is present in System.Collections.Generic namespace. The Stack collection class is analogous to a stack of plates. If you want to add a new plate to the stack of plates, you place it on top of all the already existing plates.If you want to remove a plate from the stack, you will first remove the one that you have last added. The stack collection class also operates in a similar fashion. The last item to be added (pushed) to the stack, will be the first item to be removed (popped) from the stack. To insert an item at the top of the stack, use Push() method. To remove and return the item that is present at the top of the stack, use Pop() method. A foreach loop iterates thru the items in the stack, but will not remove them from the stack. The items from the stack are retrieved in LIFO (Last In First Out), order. The last element added to the Stack is the first one to be removed. To check if an item exists in the stack, use Contains() method. What is the difference between Pop() and Peek() methods? Pop() method removes and returns the item at the top of the stack, where as Peek() returns the item at the top of the stack, without removing it.