3 ms·
The method exists in both IEnumerable<T> and Collection<T> (I do not remember exact class, but it was something simple like List`1). The difference is when you
by omgtehlion 9y ago
The method exists in both IEnumerable<T> and Collection<T> (I do not remember exact class, but it was something simple like List`1).
The difference is when you use IEnumerable<T> user method (provided as extension, using IEnum) has to call IEnumerator GetEnumerator() and allocate it on a heap. But that collection have its own implementation which works faster than generic one.
- joshjje 9y agoYeah I believe you are talking about enumerating over the interface versus the concrete class? (For others) Most of .NET frameworks generic collections implement the enumerator as a struct which doesnt get allocated on the heap and subsequently garbage collected, but the explicit interfaces implementations use a class which does.