开发者

Are LINQ .Last, .Skip, etc. methods optimized for arrays or List<T>?

I'm wondering if LINQ methods like .Last and .Skip are optimized for arrays, List<T> and such. E.g. for an array I could do _array[_array.Length - 1] to get the last element.开发者_如何学Python Does _array.Last() actually enumerate through all elements and then return the last or is there actually some optimization built in?

Might have to forgo fluency for performance if not.


Last() is optimized when there isn't a predicate... it could be optimized even if there is a predicate (by working back from the end), but it isn't.

I don't think Skip is optimized - although again, it could be.

Basically most of LINQ to Objects is optimized where it can be (for ICollection<T>, ICollection, and IList<T>) but there's still room for more to come.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜