2012-04-17 30 views

回答

44

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()) 
{ 

} 
+0

+1对于Any()'推荐。 – devgeezer 2012-04-18 07:25:43

相关问题