fork download
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. public class Lists
  5. {
  6. static void Main()
  7. {
  8.  
  9. List <string> surfbreakList = new List<string> ();
  10.  
  11. surfbreakList.Add ("Mavericks");
  12. surfbreakList.Add ("Teahupoo");
  13. surfbreakList.Add ("Jaws");
  14. surfbreakList.Add ("Nazare");
  15. surfbreakList.Add ("Nahant Beach");
  16.  
  17. Console.WriteLine ("\nMy Favorite Surf Break List: ");
  18. foreach (string surfbreak in surfbreakList)
  19. {
  20. Console.WriteLine ( surfbreak );
  21. }
  22.  
  23. surfbreakList.Remove ("Nahant Beach");
  24. surfbreakList.Insert (2, "Cocoa Beach");
  25.  
  26.  
  27. Console.WriteLine ("\nAfter removing Nahant Beach and adding Cocoa Beach, the list is: ");
  28. foreach (string surfbreak in surfbreakList)
  29. {
  30. Console.WriteLine ( surfbreak );
  31. }
  32.  
  33. Console.WriteLine ("\nThe Index of Teahupoo is:");
  34. Console.WriteLine(surfbreakList.IndexOf ("Teahupoo") );
  35.  
  36. // sort and print the list
  37. surfbreakList.Sort ();
  38.  
  39. Console.WriteLine ("\nMy current surfing surf break list sorted is:");
  40. foreach (string surfbreak in surfbreakList)
  41. {
  42. Console.WriteLine ( surfbreak );
  43. }
  44. // Cout the size of the list
  45. Console.WriteLine("\nCount of breaks in the list is: " + surfbreakList.Count + "\n");
  46.  
  47. } // main
  48.  
  49.  
  50. } // public class lists
Success #stdin #stdout 0.03s 27412KB
stdin
Standard input is empty
stdout
My Favorite Surf Break List: 
Mavericks
Teahupoo
Jaws
Nazare
Nahant Beach

After removing Nahant Beach and adding Cocoa Beach, the list is: 
Mavericks
Teahupoo
Cocoa Beach
Jaws
Nazare

The Index of Teahupoo is:
1

My current surfing surf break list sorted is:
Cocoa Beach
Jaws
Mavericks
Nazare
Teahupoo

Count of breaks in the list is: 5