AsNullSafeEnumerable

public static System.Collections.Generic.IEnumerable<T> AsNullSafeEnumerable<T>(this System.Collections.Generic.IEnumerable<T> collection) {
	if (collection.IsNotNullNorZero()) {
		return collection;
	} else {
		return new T[] { };
	}
}
Example:
string[] names = null;
foreach (var name in names.AsNullSafeEnumerable()) {
	Console.WriteLine("Hello, {0}", name);
}

Description

You don't need check whether the collection is null.

Details

Double click on the code to select all.

 

;