Are LINQ.Last, .Skip, etc. optimized? Methods for arrays or List <T>?
I am wondering if LINQ methods such as .Last and .Skip for arrays, List<T> , etc. For instance. for an array, I could do _array[_array.Length - 1] to get the last element. Does _array.Last() list all the elements and then return the last, or is the optimization really built?
You may have to refuse execution if not.
+4
1 answer
Last() optimized when there is no predicate ... it can be optimized even if there is a predicate (from working from the end), but it is not.
I don't think Skip optimized - although, again, it could be.
Basically, most LINQ to Objects are optimized where they can be (for ICollection<T> , ICollection and IList<T> ), but there is still room for even more.
+5