static void TestDictionaryInSensitive() { try { var comparer = StringComparer.OrdinalIgnoreCase; Dictionary<string, string> dic = new Dictionary<string, string>(comparer); dic.Add("Hello", "World"); dic.Add("hello", "world"); } catch(Exception ex) { Console.WriteLine(ex.Message); } }
Run the abvoe demo,it will raise an exception with "An item with the same key has already been added." message