Getting a KeyValuePair<> directly from a Dictionary<>

后端 未结 4 1368
忘了有多久
忘了有多久 2021-01-03 18:15

I have System.Collections.Generic.Dictionary dict where A and B are classes, and an instance A a (where dict.ContainsKey(a)

4条回答
  •  清酒与你
    2021-01-03 18:41

    As Dictionary implements IEnumerable>, you could use linq:

    var pair = _dictionary.SingleOrDefault(p => p.Key == myKey);
    

提交回复
热议问题