// Naomi Jones
// Survey, Summer 2025
// July 6, 2025
// Assignment 6 - 2 C# Dictionary
using System;
using System.Collections.Generic;
namespace DictionaryOpera
{
class Program
{
static void Main(string[] args)
{
// Creates a dictionary in which both keys and values are strings.
Dictionary<string, string> dict = new Dictionary<string, string>();
// Add items to the dictionary. Each has a key and a value.
dict.Add("Don Giovanni", "Serial seducer ends up in hell.");
dict.Add("Un Ballo in Maschera", "Everyone ends up at a masked ball where someone gets stabbed.");
dict.Add("Aida", "Unhappy love triangle.");
dict.Add("Der fliegende Holländer", "A ghostly captain gets a shot at redemption every seven years.");
dict.Add("Fidelio", "Cosplay jail break.");
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.");
// Decided to remove Fidelio and add Gotterdammerung.
dict.Remove("Fidelio");
dict.Add("Gotterdammerung", "The last chapter of 15 hours of opera.");
// Displays the contents of the dictionary.
Console.WriteLine("A list of favorite operas: ");
foreach (KeyValuePair<string, string> pair in dict)
{
// String methods to format the output since both are strings.
Console.WriteLine("Key: " + pair.Key.PadRight(25) + " Value: " + pair.Value);
}
// Method to check if particular keys are contained in the dictionary.
Console.WriteLine ("\nUsing the ContainsKey method to see if an opera exists in the dictionary:");
Console.WriteLine ("Contains key Carmen " + dict.ContainsKey ("Carmen"));
Console.WriteLine ("Contains key La Boheme " + dict.ContainsKey ("La Boheme"));
Console.WriteLine ("Contains key Don Giovanni " + dict.ContainsKey ("Don Giovanni"));
// Retrieving just the keys.
Console.WriteLine ("\nPrinting just the keys:");
Dictionary<string, string>.KeyCollection keys = dict.Keys;
foreach(string key in keys)
{
Console.WriteLine ("Key: " + key);
}
} // main
} // Program class
} // DictionaryOpera namespace