linq-Empty
源码:
public static IEnumerable<TResult> Empty<TResult>() { return EmptyEnumerable<TResult>.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<TElement> { public static readonly TElement[] Instance = new TElement[0]; }
public static IEnumerable<TSource> DefaultIfEmpty<TSource>(this IEnumerable<TSource> source) { return DefaultIfEmpty(source, default(TSource)); } public static IEnumerable<TSource> DefaultIfEmpty<TSource>(this IEnumerable<TSource> source, TSource defaultValue) { if (source == null) throw Error.ArgumentNull("source"); return DefaultIfEmptyIterator<TSource>(source, defaultValue); }