It's a common situation to copy a range from an array. C# supports this operation in various ways, for instance using Array.Copy, but also by Linq's Skip and Take combination.
Starting at .NET 4.0, do the Skip and Take operations still add considerable overhead, or do they recognize (either at compile time or at run time) their target is an array?
To clarify: I am referring to a) the time taken to skip the initial bytes and b) to the combination of Skip-Take-ToArray, which does not suffer from side effects. For instance, new byte[10000].Skip(9999).Take(1).ToArray()
could be optimized this way and would (for large n) be noticeably faster.
.Skip(1)
on a 10,000,000 element array - are you expecting a 9,999,999 element memory copy? That would be very inefficient if I then immediately did a.Take(1)
. – HasletSkip
. Anyway, neitherSkip
norTake
copy the source collection. – Asper