Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LINQ Operator '==' cannot be applied to operands of type 'method group' and 'int'

Tags:

I have something like the following:

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

I get a swigly lie under lst.Count == 0 and it says:

Operator '==' cannot be applied to operands of type 'method group' and 'int'

like image 806
Nate Pet Avatar asked Apr 17 '12 21:04

Nate Pet


1 Answers

Enumerable.Count is an extension method, not a property. This means usp_GetLst probably returns IEnumerable<T> (or some equivalent) rather than a derivative of IList<T> or ICollection<T> which 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()) {  } 
like image 61
user7116 Avatar answered Oct 18 '22 20:10

user7116