C# dictionary keys case insensitive

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

原文地址:https://www.cnblogs.com/Fred1987/p/14333935.html