Skip to content

Instantly share code, notes, and snippets.

@sclarson
Forked from cammerman/ExtMethod.cs
Created August 2, 2011 18:41
Show Gist options
  • Save sclarson/1120870 to your computer and use it in GitHub Desktop.
Save sclarson/1120870 to your computer and use it in GitHub Desktop.
IEnumerable Null Check
public static class IEnumerableExtensions
{
public static IEnumerable<T> OrEmptyListIfNull<T>(this IEnumerable<T> source)
{
return source ?? Enumerable.Empty<T>();
}
}
foreach (var item in items.OrEmptyListIfNull())
{
//do something
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment