Extension Method for returning default values static class ExtensionsThatWillAppearOnEverything { public static T IfDefaultGiveMe < T >( this T value , T alternate ) { if ( value . Equals ( default ( T ))) return alternate ; return value ; } } var result = query . FirstOrDefault (). IfDefaultGiveMe ( otherDefaultValue ); Or we can use the one shown below ,though its not an extension method. var result = query . FirstOrDefault () ?? otherDefaultValue ;
I jot down whatever I learn from different sources.Written for personal use. But anyone can learn.