In general Slower. LINQ's Count in general is an O(N)
operation while List.Count
and Array.Length
are both guaranteed to be O(1)
.
However it some cases LINQ will special case the IEnumerable<T>
parameter by casting to certain interface types such as IList<T>
or ICollection<T>
. It will then use that Count method to do an actual Count()
operation. So it will go back down to O(1)
. But you still pay the minor overhead of the cast and interface call.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…