var key = Dic_BandRate.Single(k => k.Value == 9600).Key;
如果有可能值不存在,那么就用SingleOrDefault var keyvaluepair = Dic_BandRate.SingleOrDefault(k => k.Value == 9600);
var key = keyvaluepair == null ? 0 : keyvaluepair.Key;
------解决方案-------------------- 给出我自己的思路
C# code
Dictionary<int, int> Dic_BandRate = new Dictionary<int, int>()
{
{10,115200},{11,57600},{12,38400},{13,19200},{14,9600},{15,4800}
};
var query = from d in Dic_BandRate
where d.Value == 9600
select d.Key;
Console.WriteLine(query.FirstOrDefault());