Hi
Consider this code:
int size = 100 * 1000 * 1000;
var emu = Enumerable.Range(0, size);
var arr = Enumerable.Range(0, size).ToArray();
when I call emu.ElementAt(size-10) and arr.ElementAt(size-10) and measure the time the arr is much faster (the array is 0.0002s compared to IEnumerable 0.59s).
As I understand it, the extention method ElementAt() have the signature
public static TSource ElementAt<TSource>(this IEnumerable<TSource> source, int index)
and since the 'source' is a IEnumerable the logic carried out would be similar - opposed to what I see where the array is accessed directly.
Could someone please explain this :)