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. // Creates list to store opera names.
  14. List<string> operaList = new List<string>();
  15.  
  16. // Adds operas to the list.
  17. operaList.Add("Don Giovanni");
  18. operaList.Add("Un ballo in maschera");
  19. operaList.Add("Aida");
  20. operaList.Add("Der fliegende Hollander");
  21. operaList.Add("Fidelio");
  22. operaList.Add("Turandot");
  23.  
  24. // Decided that Gotterdammerung should be on the list instead of Fidelio.
  25. operaList.Remove("Fidelio");
  26. operaList.Insert(5, "Gotterdammerung");
  27.  
  28. // Sorting the list.
  29. operaList.Sort();
  30.  
  31. // Displays list of operas.
  32. Console.WriteLine("A list of favorite operas: ");
  33. foreach (string opera in operaList)
  34. {
  35. Console.WriteLine(opera);
  36. }
  37.  
  38. // Checking if these operas are contained in the list.
  39. Console.WriteLine("\nChecking if these operas are contained in the list: ");
  40. Console.WriteLine("Carmen: " + operaList.Contains("Carmen"));
  41. Console.WriteLine("La Boheme: " + operaList.Contains("La Boheme"));
  42. Console.WriteLine("Don Giovanni: " + operaList.Contains("Don Giovanni"));
  43.  
  44. } // main
  45.  
  46. } // class Opera
Success #stdin #stdout 0.07s 28432KB
stdin
Standard input is empty
stdout
A list of favorite operas: 
Aida
Der fliegende Hollander
Don Giovanni
Gotterdammerung
Turandot
Un ballo in maschera

Checking if these operas are contained in the list: 
Carmen: False
La Boheme: False
Don Giovanni: True