Something like this should work for you:
public static IsEmpty(this IEnumerable list) { IEnumerator en = list.GetEnumerator(); return !en.MoveNext(); }
Just start the listing, and if you can go to the first element, it will not be empty. Alternatively, you can check if IEnumerable implements ICollection, and if so, call its .Count property.
source share