2012-04-17 12 views
7

मैं निम्नलिखित की तरह कुछ है करने के लिए लागू नहीं किया जा सकता और यह कहते हैं:LINQ ऑपरेटर '==' प्रकार 'विधि समूह' और 'int' की ऑपरेंड

ऑपरेटर '==' प्रकार 'विधि समूह' और 'int' की ऑपरेंड के लिए लागू नहीं किया जा सकता

उत्तर

44

Enumerable.Count एक विस्तार विधि, नहीं एक संपत्ति है। इसका अर्थ है usp_GetLst शायद IList<T> या ICollection<T> के व्युत्पन्न के बजाय IEnumerable<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 'किसी भी()' सिफारिश के लिए +1। – devgeezer

संबंधित मुद्दे