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
Without custom helpers I recommend either ?.Any() ?? false or ?.Any() == true which are relatively concise and only need to specify the sequence once.
When I want to treat a missing collection like an empty one, I use the following extension method:
public static IEnumerable OrEmpty(this IEnumerable sequence)
{
return sequence ?? Enumerable.Empty();
}
This function can be combined with all LINQ methods and foreach, not just .Any(), which is why I prefer it over the more specialized helper functions people are proposing here.