LINQ operator '==' cannot be applied to operands of type "method group" and "int",

I have something like the following:

var lst = db.usp_GetLst(ID,Name, Type); if (lst.Count == 0) { } 

I get swigly false under lst.Count == 0, and it says:

The operator '==' cannot be applied to operands of the type "method group" and "int"

+7
source share
1 answer

Enumerable.Count is an extension method, not a property. This means that usp_GetLst probably returns an IEnumerable<T> (or some equivalent), and not the derivative of IList<T> or ICollection<T> that you expected.

 // Notice we use lst.Count() instead of lst.Count if (lst.Count() == 0) { } // However lst.Count() may walk the entire enumeration, depending on its // implementation. Instead favor Any() when testing for the presence // or absence of members in some enumeration. if (!lst.Any()) { } 
+44
source

All Articles