Originally i wanted to know whether ToList
allocates more memory than using the constructor of List
which takes an IEnumerable
I guess that:
Enumerable.Range(1, 10000000)
only creates an IEnumerable and doesn't create items yet.
Enumerable.Range(1, 10000000).ToArray()
creates an array, using memory for the numbers
Enumerable.Range(1, 10000000).ToList()
creates the numbers and additional data to manage the list (links between parts. The list can change its size and needs to allocate memory in blocks).