Ask a questionAsk a question
 

QuestionInefficiency in Enumerable.Count with covariance

  • Tuesday, May 19, 2009 9:56 PMOren Novotny Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I didn't see a forum for .NET 4.0 BCL, so here goes.

    Now that IEnumerable is covariant, some of the methods in Linq to Objects run slower than expected.  For example. Count().  Count checks to see if the input implements ICollection<TSource> and if so, shortcuts and returns .Count.  With a covariant IEnumerable though, it won't.  The easy workaround is for Enumerable.Count() to also check for the non-generic ICollection and if so return Count there.  As Count (and other similar methods, aren't type-specific, then it works.

    I've bugged it here:
    https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=454130

    Thoughts?
    • Moved bynobugzMVPTuesday, May 19, 2009 10:12 PM (From:.NET Base Class Library)
    •