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);
        }

 

posted @ 2021-11-16 16:05  vba是最好的语言  阅读(33)  评论(0编辑  收藏  举报