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

C# dictionary keys case insensitive

上一篇:.net5 core webapi项目实战之七:F3管理员修改用户角色


下一篇:基于Windows服务实现的亚马逊云S3文件上传