fork download
  1. // Naomi Jones
  2. // Survey, Summer 2025
  3. // July 6, 2025
  4. // Assignment 6 - 2 C# Dictionary
  5.  
  6. using System;
  7. using System.Collections.Generic;
  8.  
  9. namespace DictionaryOpera
  10. {
  11. class Program
  12. {
  13. static void Main(string[] args)
  14. {
  15. // Creates a dictionary in which both keys and values are strings.
  16. Dictionary<string, string> dict = new Dictionary<string, string>();
  17.  
  18. // Add items to the dictionary. Each has a key and a value.
  19. dict.Add("Don Giovanni", "Serial seducer ends up in hell.");
  20. dict.Add("Un Ballo in Maschera", "Everyone ends up at a masked ball where someone gets stabbed.");
  21. dict.Add("Aida", "Unhappy love triangle.");
  22. dict.Add("Der fliegende Holländer", "A ghostly captain who can't hold down a relationship gets a shot at redemption every seven years.");
  23. dict.Add("Gotterdammerung", "The last chapter of 15 hours of opera.");
  24. dict.Add("Turandot", "Princess gives death-or-marriage riddles, a bold prince takes a chance, and everyone stays up all night trying to figure out who he is.");
  25.  
  26. // Displays the contents of the dictionary.
  27. Console.WriteLine("\nA list of favorite operas: ");
  28. foreach (KeyValuePair<string, string> pair in dict)
  29. {
  30. // String methods to format the output since both are strings.
  31. Console.WriteLine("Key: " + pair.Key.PadRight(25) + " Value: " + pair.Value);
  32. }
  33. } // main
  34.  
  35. } // Program class
  36.  
  37. } // DictionaryOpera namespace
  38.  
Success #stdin #stdout 0.06s 28864KB
stdin
Standard input is empty
stdout
A list of favorite operas: 
Key: Don Giovanni              Value: Serial seducer ends up in hell.
Key: Un Ballo in Maschera      Value: Everyone ends up at a masked ball where someone gets stabbed.
Key: Aida                      Value: Unhappy love triangle.
Key: Der fliegende Holländer   Value: A ghostly captain who can't hold down a relationship gets a shot at redemption every seven years.
Key: Gotterdammerung           Value: The last chapter of 15 hours of opera.
Key: Turandot                  Value: Princess gives death-or-marriage riddles, a bold prince takes a chance, and everyone stays up all night trying to figure out who he is.