linq-Empty
源码:
public static IEnumerableEmpty () { return EmptyEnumerable .Instance; }
// // We have added some optimization in SZArrayHelper class to cache the enumerator of zero length arrays so // the enumerator will be created once per type. // internal class EmptyEnumerable{ public static readonly TElement[] Instance = new TElement[0]; }
public static IEnumerableDefaultIfEmpty (this IEnumerable source) { return DefaultIfEmpty(source, default(TSource)); } public static IEnumerable DefaultIfEmpty (this IEnumerable source, TSource defaultValue) { if (source == null) throw Error.ArgumentNull("source"); return DefaultIfEmptyIterator (source, defaultValue); }