Stack Concept in .Net

A collection that works on the Last In First Out (LIFO) principle,
i.e., the last item inserted is the first item removed from the collection.
Push - To add element and
Pop – To Remove element

Example

using System;
using System.Collections;

class Test
{
static void Main()
{
Stack stack = new Stack();
stack.Push(2);
stack.Push(4);
stack.Push(6);

while(stack.Count != 0)
{
Console.WriteLine(stack.Pop());
}
}
}

Output

6
4
2

2 comments:

Jed said...

A file is used to store the names of the students. If a stack concept is used to insert or remove the names from the file, show how the following names will be inserted or removed in the sequence as follows:
a)push “Rose”
b)push “Melinda”
c)pop
d)push “Jerry”
e)push “Danny”
f)pop

please send to my account Jed_XI@yahoo.com

Rahul said...

hi,

First of all. Thanks very much for your useful post.

I just came across your blog and wanted to drop you a note telling you how impressed I was with the information you have posted here.

Please let me introduce you some info related to this post and I hope that it is useful for .Net community.

There is a good C# resource site, Have alook

http://www.csharptalk.com/2009/09/c-array.html
http://www.csharptalk.com/2009/10/creating-arrays.html

simi

Most Recent Post

Most Recent Ado.net FAQ

Most Recent .Net Framework FAQ

Most Recent Configuration Files FAQ

Daily Quote, Inspiration, Motivation and More

Subscribe Blog via Email

Enter your email address: