Welcome to mirror list, hosted at ThFree Co, Russian Federation.

LowLevelEnumerable.ToList.cs « LowLevelLinq « Internal « Common « tools « coreclr « src - github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8ab46e8b8caeadd8e1e77eb9b3d50b9be874e505 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics;
using System.Collections.Generic;

namespace Internal.LowLevelLinq
{
    internal static partial class LowLevelEnumerable
    {
        public static List<T> ToList<T>(this IEnumerable<T> source)
        {
            List<T> result;

            var collection = source as ICollection<T>;
            if (collection != null)
                result = new List<T>(collection.Count);
            else
                result = new List<T>();

            foreach (var element in source)
                result.Add(element);

            return result;
        }
    }
}