Skip to content

Instantly share code, notes, and snippets.

@MichalGrzegorzak
Forked from sclarson/ExtMethod.cs
Created February 12, 2013 08:38
Show Gist options
  • Save MichalGrzegorzak/4760992 to your computer and use it in GitHub Desktop.
Save MichalGrzegorzak/4760992 to your computer and use it in GitHub Desktop.
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