Reputation: 4783
I have a dictionary of key-value pairs. How can I check for where
clause failure?
SomeDictionary.Where(x => x.Value && someOtherBool).First();
Is there a way to check if this returned some result without surrounding with try-catch
block? Sure, I can call FirstOrDefault()
but I don't get what I need then...
There should really be a method FirstOrReturn(arg)
...
Upvotes: 1
Views: 173
Reputation: 45947
FirstOrReturn(arg)
should be
.Where(x => x.Value && someOtherBool).DefaultIfEmpty(arg).First();
Upvotes: 7