Demo:
var dic = new Dictionary<string, int>() { {"a",1}, {"b",2}, {"c",3}, {"d",1} }; foreach (var item in dic) { if (item.Value == 1) { Console.WriteLine(item.Key); } }
非常感谢你的帮助
Dictionary<string,string> dic =newDictionary<string,string>() {{"1","one"},}; var key_by_value = dic.Where(p => p.Value=="one").Select(p => p.Key); foreach(var key in key_by_value ){....}
非常感谢你的帮助
正解
var dic = new Dictionary<string, int>() { {"a",1}, {"b",2}, {"c",3}, {"d",1} }; Console.WriteLine(dic.FirstOrDefault(x => x.Value == 2).Key);
非常感谢你的帮助