I have Dictionary from string key i want to get Value of corresponding 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With