Case insensitive access for generic dictionary

前端 未结 4 647
梦毁少年i
梦毁少年i 2020-11-28 02:31

I have an application that use managed dlls. One of those dlls return a generic dictionary:

Dictionary MyDictionary;  

4条回答
  •  攒了一身酷
    2020-11-28 02:55

    Its not very elegant but in case you cant change the creation of dictionary, and all you need is a dirty hack, how about this:

    var item = MyDictionary.Where(x => x.Key.ToLower() == MyIndex.ToLower()).FirstOrDefault();
        if (item != null)
        {
            TheValue = item.Value;
        }
    

提交回复
热议问题