首页 > Windows开发 > 详细

C# dictionary keys case insensitive

时间:2021-01-27 14:22:29      阅读:24      评论:0      收藏:0      [点我收藏+]
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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!