Skip to content

Instantly share code, notes, and snippets.

@JeffreyZhao
Created April 8, 2014 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeffreyZhao/10084967 to your computer and use it in GitHub Desktop.
Save JeffreyZhao/10084967 to your computer and use it in GitHub Desktop.
public static IEnumerable<TResult> SelectNonNull<TSource, TResult>(
this IEnumerable<TSource> source,
Func<TSource, TResult> selector)
where TResult : class
{
return source != null ? source.Select(selector).Where(i => i != null) : Enumerable.Empty<TResult>();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment