Is there a l lambda linq search method that returns null instead of throwing an exception when searching in a list?
My current solution is something like: (to throw an exception from an exception)
if (list.Exists(x => x.Foo == Foo)) { var listItem = list.Find(x => x.Foo == Foo); }
It is simply wrong to repeat the expression.
Something like...
var listItem = list.Find(x => x.Foo == Foo); if (listItem != null) {
... I'm better. Or is it just me?
Do you have a better approach to this? (The solution does not have to return zero, just the best solution is good)
Ben Galler Apr 10 2018-11-11T00: 00Z
source share