.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Steve Jackman
Imran Ghani
Santhakumar Munuswamy

Home >> Forum >> OOPS >> Post New QuestionBookmark and Share Subscribe to Forum

Store and retrive value from stack

Posted By: Rajesh     Posted Date: April 08, 2010    Points:2   Category :OOPS
how can we store a value directly into stack? and how we can retrieve in .net framework.

Responses
Author: Dilip             
Posted Date: April 08, 2010     Points: 5   

Stack in .Net comes under Generic Collection. Reason behind you are push/pod data items of any type in stack.

Just these lines of code will give you are idea: I hope the you know the terminologies of Stack i.e. Push / Pop
----------------------------------------------------------

static void Main(string[] args)
{
Stack<int> stk = new Stack<int>(10);
stk.Push(10);
stk.Push(20);
stk.Push(30);
stk.Push(40);
stk.Push(50);
stk.Push(60);
stk.Push(70);

Console.WriteLine(stk.Count.ToString());

stk.Pop();

Console.WriteLine(stk.Count.ToString());

Console.Read();
}

Regards
Dilip
Author: Rajesh             
Posted Date: April 09, 2010     Points: 5   

thank u for quick replay

Author: Vinodh             
Posted Date: September 16, 2011     Points: 20   

public static void Main()
{
Stack mystack = new Stack();
mystack.push("one");
mystack.push(1);
mystack.push(1.111);

foreach(object value in mystack)
Console.WriteLine(value);
}

advantage : stack stores objects in it, than value type



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend