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> colorList = new List<string>();
  10.  
  11. colorList.Add ("Red");
  12. colorList.Add ("Green");
  13. colorList.Add ("Yellow");
  14. colorList.Add ("Purple");
  15. colorList.Add ("Orange");
  16.  
  17. Console.WriteLine ("\nMy initial list of colors is: ");
  18. foreach (string color in colorList)
  19. {
  20. Console.WriteLine ( color );
  21. }
  22.  
  23. colorList.Remove ("Red");
  24. colorList.Insert (2, "White");
  25.  
  26.  
  27. Console.WriteLine ("\nAfter removing Red and adding White, my list is: ");
  28. foreach (string color in colorList)
  29. {
  30. Console.WriteLine ( color );
  31. }
  32.  
  33. Console.WriteLine ("\nThe Index of Yellow is:");
  34. Console.WriteLine(colorList.IndexOf ("Yellow") );
  35.  
  36. // sort and print your list
  37. colorList.Sort ();
  38.  
  39.  
  40.  
  41. } // main
  42.  
  43.  
  44. } // public class lists
  45.  
Success #stdin #stdout 0.03s 27336KB
stdin
Standard input is empty
stdout
My initial list of colors is: 
Red
Green
Yellow
Purple
Orange

After removing Red and adding White, my list is: 
Green
Yellow
White
Purple
Orange

The Index of Yellow is:
1