public static TSource[] ToArray <TSource>(this IEnumerable <TSource> source)
        {
            switch (source)
            {
            case TSource[] array:
                return(array);

            case IReadOnlyList <TSource> list:
                return(ReadOnlyList.ToArray <IReadOnlyList <TSource>, IEnumerator <TSource>, TSource>(list));

            case IReadOnlyCollection <TSource> collection:
                return(ReadOnlyCollection.ToArray <IReadOnlyCollection <TSource>, IEnumerator <TSource>, TSource>(collection));

            default:
                return(Enumerable.ToArray <IEnumerable <TSource>, IEnumerator <TSource>, TSource>(source));
            }
        }
示例#2
0
 public static TSource[] ToArray <TSource>(this List <TSource> source)
 => ReadOnlyList.ToArray <List <TSource>, List <TSource> .Enumerator, TSource>(source);
示例#3
0
 public static TSource[] ToArray <TSource>(this ImmutableList <TSource> source)
 => ReadOnlyList.ToArray <ImmutableList <TSource>, TSource>(source);
 public static TSource[] ToArray <TSource>(this IReadOnlyList <TSource> source)
 => ReadOnlyList.ToArray <IReadOnlyList <TSource>, IEnumerator <TSource>, TSource>(source);