C# dictionary keys case insensitive
时间:2021-01-27 14:22:29
收藏:0
阅读:24
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
评论(0)