fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections; // For old-style ArrayList
  4. class StackSample
  5. {
  6.  
  7. static void Main(string[] args)
  8. {
  9. Stack surfbreakStack = new Stack();
  10. surfbreakStack.Push ("Mavericks");
  11. surfbreakStack.Push ("Teahupoo");
  12. surfbreakStack.Push ("Jaws");
  13. surfbreakStack.Push ("nazare");
  14. surfbreakStack.Push ("Cocoa Beach");
  15. surfbreakStack.Push ("Nahant Beach"); // ... wait a minute ... Nahant is only good in February
  16. surfbreakStack.Pop (); // remove Nahant Beach
  17.  
  18.  
  19. Console.WriteLine("This is a stack of my favorite Surf Breaks ...");
  20.  
  21. // print all of my favorite movies
  22. foreach(string surfbreak in surfbreakStack) {
  23. Console.WriteLine(surfbreak);
  24. } // foreach
  25.  
  26. Console.WriteLine("\n\nPopping breaks from the Stack ...\n");
  27.  
  28. while(surfbreakStack.Count > 0) {
  29. string surfbreak = (string) surfbreakStack.Pop ();
  30. Console.WriteLine("Popping {0}", surfbreak );
  31. } // while
  32.  
  33. } // main
  34.  
  35. }
Success #stdin #stdout 0.03s 24344KB
stdin
Standard input is empty
stdout
This is a stack of my favorite Surf Breaks  ...
Cocoa Beach
nazare
Jaws
Teahupoo
Mavericks


Popping breaks from the Stack ...

Popping Cocoa Beach
Popping nazare
Popping Jaws
Popping Teahupoo
Popping Mavericks