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
- Author: Rrr
- Submitted on: 31-3-2011 16:06:45
- Language: C#
- Type: System.Collections.Generic.IEnumerable<T>
- Views: 2407
Double click on the code to select all.