fork download
  1. // Naomi Jones
  2. // Survey, Summer 2025
  3. // July 6, 2025
  4. // Assignment 6 - 1 C# Lists
  5.  
  6. using System;
  7. using System.Collections.Generic;
  8.  
  9. public class Opera
  10. {
  11. static void Main()
  12. {
  13.  
  14. // Creates list to store opera names.
  15. List <string> operaList = new List<string> ();
  16.  
  17. // Adds operas to the list.
  18. operaList.Add ("Don Giovanni");
  19. operaList.Add ("Un ballo in maschera");
  20. operaList.Add ("Aida");
  21. operaList.Add ("Der fliegende Hollander");
  22. operaList.Add ("Gotterdammerung");
  23. operaList.Add ("Turandot");
  24.  
  25. // Displays list of operas.
  26. Console.WriteLine ("\nA list of favorite operas: ");
  27. foreach (string opera in operaList)
  28. {
  29. Console.WriteLine ( opera );
  30. }
  31.  
  32. operaList.Remove ("Gotterdammerung");
  33. operaList.Insert (2, "Fidelio");
  34.  
  35.  
  36. Console.WriteLine ("\nAfter removing Gotterdammerung and adding Fidelio, my list is: ");
  37. foreach (string opera in operaList)
  38. {
  39. Console.WriteLine ( opera );
  40. }
  41.  
  42. // Sort and prints the list.
  43. operaList.Sort ();
  44.  
  45. Console.WriteLine ("\nMy current opera list sorted is:");
  46. foreach (string opera in operaList)
  47. {
  48. Console.WriteLine ( opera );
  49. }
  50.  
  51. } // main
  52.  
  53. } // class Opera
Success #stdin #stdout 0.05s 30276KB
stdin
Standard input is empty
stdout
A list of favorite operas: 
Don Giovanni
Un ballo in maschera
Aida
Der fliegende Hollander
Gotterdammerung
Turandot

After removing Gotterdammerung and adding Fidelio, my list is: 
Don Giovanni
Un ballo in maschera
Fidelio
Aida
Der fliegende Hollander
Turandot

My current opera list sorted is:
Aida
Der fliegende Hollander
Don Giovanni
Fidelio
Turandot
Un ballo in maschera