I really like Last()
and would use it all the time for List<T>
s. But since it seems to be defined for IEnumerable<T>
, I guess it enumerates the enumeration first - this should be O(n) as opposed to O(1) for directly indexing the last element of a List<T>
.
Are the standard (Linq) extension methods aware of this?
The STL in C++ is aware of this by virtue of a whole "inheritance tree" for iterators and whatnot.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…