IEnumerable doesn’t have a Count method

You add:

using System.Linq;

at the top of your source and make sure you’ve got a reference to the System.Core assembly.

Count() is an extension method provided by the System.Linq.Enumerable static class for LINQ to Objects, and System.Linq.Queryable for LINQ to SQL and other out-of-process providers.

EDIT: In fact, using Count() here is relatively inefficient (at least in LINQ to Objects). All you want to know is whether there are any elements or not, right? In that case, Any() is a better fit:

public bool IsValid
{
  get { return !GetRuleViolations().Any(); }
}

Leave a Comment