This post originated from an RSS feed registered with .NET Buzz
by Oliver Sturm.
Original Post: Getting the number of items in an IEnumerable
Feed Title: Oliver Sturm's weblog
Feed URL: https://oliversturm.com/blog/blog/archives/category/programming/net/feed/
Feed Description: General musings and programming stuff, .NET category
int GetCount(IEnumerable enumerable) {
int count = 0;
foreach (object o in enumerable)
count++;
return count;
}
It’s that simple, right? Well, no, it isn’t. What you have to realize is that in contrast to ICollection, IList or IBindingList, IEnumerable is not an interface that’s by definition used with some kind [...]