ReSharper 2017.3 Help

Code Inspection: Use collection’s count property

If a collection has a Count property (or a Length property), ReSharper suggests using the property instead of the Count() method. The property works faster (to see why, read the StackOverflow answers linked in the See Also below). Such a replacement is only possible for collections that implement ICollection<T> or its derived interfaces.

For arrays, ReSharper suggests replacing Count() with Length:

Suboptimal codeAfter the quick-fix
public int BooksCount(string[] books) { return books.Count(); }
public int BooksCount(string[] books) { return books.Length; }

For other collection types, ReSharper suggests replacing Count() with Count:

Suboptimal codeAfter the quick-fix
public int ToysCount(IList<string> toys) { return toys.Count(); }
public int ToysCount(IList<string> toys) { return toys.Count; }
Last modified: 7 December 2017

See Also