Reactions to story from Omer van Kloeten's .NET Zen
Linq: FirstOrFallback
http://weblogs.asp.net/ okloeten/ archive/ 2008/ 04/ 23/ 6123904.aspx
Sometimes you want to use FirstOrDefault, but the default value of T is a valid value that might get returned. If you used FirstOrDefault, you wouldn't know whether the value that you got is a valid first or the default fallback. I use FirstOrFallback to explicitly specify which fallback value I want, rather than always use default(T): public static T FirstOrFallback<T>(this IEnumerable<T> enumeration, T fallback) { // Check to see that enumeration is not null if (enumeration == null) throw new ArgumentNullException("enumeration"); IEnumerator<T> enumerator = enumeration.GetEnumerator();
More rising blog posts
-
Entertainment »
Shuhei Yoshida announced as Harrison's successor -
Business »
Yes, the Advertisements are Hosed -
Lifestyle »
USGBC Set to Open 'LEED 2009' for Public Comment -
Politics »
How to make an iPod speaker from a greetings card in six easy steps -
Sports »
New International Track and Field footage -
Technology »
Study: Cox, Comcast Internet subscribers blocked
Recent posts from Omer van Kloeten's .NET Zen
-
A Limitation of Lambda Expressions and Overloaded Extension Methods
9 days ago -
Linq to SQL: ChangeConflictException With "WHERE 0 = 1"
18 days ago -
Linq Extensions Release 2 Now on CodePlex
23 days ago