We can compare the performance of ToList and the List() constructor. ToList has some extra indirection, so this will likely cause a small performance penalty.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
const int _max = 1000000;
int[] array = new int[] { 10, 20, 30, 40, int.MaxValue, int.MinValue };
var s1 = Stopwatch.StartNew();
for (int i = 0; i < _max; i++)
{
// Version 1: use ToList.
var list = array.ToList();
if (list.Count != 6)
{
return;
}
}
s1.Stop();
var s2 = Stopwatch.StartNew();
for (int i = 0; i < _max; i++)
{
// Version 2: use List constructor.
var list = new List<int>(array);
if (list.Count != 6)
{
return;
}
}
s2.Stop();
Console.WriteLine(((double)(s1.Elapsed.TotalMilliseconds * 1000000) / _max).ToString(
"0.00 ns"));
Console.WriteLine(((double)(s2.Elapsed.TotalMilliseconds * 1000000) / _max).ToString(
"0.00 ns"));
108.43 ns ToList
102.45 ns List constructor (new List)