I love FirstOrDefault
I know all of you who are using C# 3.0 (released with .Net 3.5) have found some of the goodness that is in System.Linq. My current favorite is FirstOrDefault. This little extension method returns the first element of a list, or the first element that meets a criteria, or returns the object’s default value. If you have done work with generics, you should be familiar with default already. Default for nullable types is null. Default for value types is…it depends on the type.
Here is my old code:
This is the new code with FirstOrDefault: