Как проверить, является ли IEnumerable нулевым или пустым?C#

Место общения программистов C#
Гость
Как проверить, является ли IEnumerable нулевым или пустым?

Сообщение Гость »


Я люблю

Код: Выделить всё

string.IsNullOrEmpty
method. I'd love to have something that would allow the same functionality for IEnumerable. Is there such? Maybe some collection helper class? The reason I am asking is that in statements the code looks cluttered if the patter is

Код: Выделить всё

(mylist != null && mylist.Any())
. It would be much cleaner to have

Код: Выделить всё

Foo.IsAny(myList)
.

This post doesn't give that answer: IEnumerable is empty?.


Источник: https://stackoverflow.com/questions/504 ... l-or-empty

Вернуться в «C#»