我有以下内容:
var lst = db.usp_GetLst(ID,Name, Type);
if (lst.Count == 0)
{
}
Run Code Online (Sandbox Code Playgroud)
我在lst.Count == 0下得到了一个简单的谎言,它说:
运算符'=='不能应用于'方法组'和'int'类型的操作数
use*_*116 57
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())
{
}
Run Code Online (Sandbox Code Playgroud)