I just want to know if the implementation of LINQ protects the developer against performance hits when calling ToArray() from an Array.
For example,
var array1 = Enumerable.Range(0,short.MaxValue).ToArray(); //does the actual copy
var array2 = array1.ToArray() //is this the same object as array1?
var array3 = ((IEnumerable<int>)array2).ToArray() //what about this?
Do all three of these ToArray() calls have the same performance implications?
Other questions like this have addressed the general performance implications of ToArray(),
Is it better to call ToList() or ToArray() in LINQ queries?
Linq ToList/ToArray/ToDictionary performance
but I'm curious as to whether the implementation is "smart enough" to avoid copying elements to another array if the source is an array.
I printed all of the hash codes from array 1, 2, and 3.
Console.WriteLine(array1.GetHashCode());
Console.WriteLine(array2.GetHashCode());
Console.WriteLine(array3.GetHashCode());
and got
62476613
11404313
64923656
Since the hash codes are all different does that mean that a copy operation happened all three times?