ILookup<string, string> someList;
Cricket Sachin
Dravid
Dhoni
Football Beckham
Ronaldo
Maradona
bool status = someList.Where(x => x.Key == "Football").Where( y => y.Value == "Ronaldo")
should return true
bool status = someList.Where(x => x.Key == "Football").Where( y => y.Value == "Venus williams")
should return false
ILookup doesn't have value property, instead of looping over, is there a smarter way to get the result in few lines. the above code is not right, hoping something similar if its possible. I am new to Linq so learning better ways
The object returned from of the ILookup<TKey, TElement>.Item
property (which is what's called when you do someList[...]
) is an IEnumerable<TElement>
. So you can compare each item directly to your test value. Like this:
var status = someList["Football"].Any(y => y == "Venus Williams");
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