How to check if IEnumerable is null or empty?

The Solution to How to check if IEnumerable is null or empty? is


Sure you could write that:

public static class Utils {
    public static bool IsAny<T>(this IEnumerable<T> data) {
        return data != null && data.Any();
    }
}

however, be cautious that not all sequences are repeatable; generally I prefer to only walk them once, just in case.

~ Answered on 2011-02-18 22:47:22


Most Viewed Questions: