Get Dictionary key by using the dictionary value

前端 未结 5 1305
盖世英雄少女心
盖世英雄少女心 2020-12-28 14:40

How to get the dictionary key by using the dictionary value?

when getting the value using the key its like this:

Dictionary dic =          


        
5条回答
  •  没有蜡笔的小新
    2020-12-28 15:29

    I realize this is an old question but wanted to add something I thought of.

    If you know there will be only one key to one value and you'll have to look up via value as well as key; you can create two separate dictionaries. One with the original key as the key and value as the value and the second with the key as the value and value as the key.

    Now a side note about this; it does use up more machine resources but I'm guessing it's faster then brute forcing through LINQ and foreach.

提交回复
热议问题