Quantcast
Viewing latest article 3
Browse Latest Browse All 34

Check If IEnumerable or List Type is Empty / Null

There are three ways to check whether IEnumerable<> or List<> type is empty / null or not. == NULL .Any() .Count() In any case, you always want to combine “== null” and, either “.Any()” or “.Count()”, with OR (“||”) operator. In addition, you want to put “== null” before the other condition. The reason for this is, “if” condition goes from left to right. So, if the list object is null, it will not go to the second check, which will result in “Object reference not set to an instance...

Viewing latest article 3
Browse Latest Browse All 34

Trending Articles