LINQ运算符'=='不能应用于'method group'和'int'类型的操作数(LINQ Operator '==' cannot be applied to operands of type 'method group' and 'int')
我有以下内容:
var lst = db.usp_GetLst(ID,Name, Type); if (lst.Count == 0) { }我在lst.Count == 0下得到了一个狡猾的谎言,它说:
运算符'=='不能应用于'method group'和'int'类型的操作数
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'
最满意答案
Enumerable.Count是一个扩展方法,而不是一个属性。 这意味着usp_GetLst可能返回IEnumerable<T> (或一些等价物),而不是您期望的IList<T>或ICollection<T>的派生。
// 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()) { }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()) { }更多推荐
发布评论