Get Dictionary key by using the dictionary value

前端 未结 5 1299
盖世英雄少女心
盖世英雄少女心 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:46

    Brute force.

            int key = dic.Where(kvp => kvp.Value == "a").Select(kvp => kvp.Key).FirstOrDefault();
    

提交回复
热议问题