Consider the following code, where each key has an identical value:
IDictionary<string, string> quarterbackDictionary = new Dictionary<string, string>();
quarterbackDictionary.Add("Manning", "Manning");
quarterbackDictionary.Add("Brady", "Brady");
quarterbackDictionary.Add("Rivers", "Rivers");
My question:
- Can I remove the redundancy, so that I don't have to repeat each string twice, similar to the following:
IDictionary<string, string> quarterbackDictionary = new Dictionary<string, string>();
quarterbackDictionary.Add("Manning");
quarterbackDictionary.Add("Brady");
quarterbackDictionary.Add("Rivers");
FYI:
- I'm using a Dictionary because I want to throw on an attempt to insert a duplicate key.
- A HashSet would not throw on an attempt to insert a duplicate key.