I love string.IsNullOrEmpty method. I\'d love to have something that would allow the same functionality for IEnumerable. Is there such? Maybe some collection he
The way I do it, taking advantage of some modern C# features:
Option 1)
public static class Utils {
public static bool IsNullOrEmpty(this IEnumerable list) {
return !(list?.Any() ?? false);
}
}
Option 2)
public static class Utils {
public static bool IsNullOrEmpty(this IEnumerable list) {
return !(list?.Any()).GetValueOrDefault();
}
}
And by the way, never use Count == 0 or Count() == 0 just to check if a collection is empty. Always use Linq's .Any()