Get Value from key using linq
Why do you want to get a value from a Dictionary using LINQ? You can just get the value using:
int value = dictionary[key];
You could use Single
, but it's totally pointless and more code:
var keyValuePair = dictionary.Single(x => x.Key == key);
int value = keyValuePair.Value;
Why use Linq for something that is built in?
var val = myDict[key];
Use Linq where it makes sense (querying collections), not for something that is already well handled by the Dictionary
classes.