The IEnumerable extension method FirstOrDefault didn\'t exactly do as I wanted so I created FirstOrValue. Is this a good way to go about this or is there a better way?
default(T) will return null by default for reference types.
default(T)
null
I would do this
public static T FirstOrValue(this IEnumerable source, Func predicate, T value) { T first = source.FirstOrDefault(predicate); return first ?? value; }