JetBrains Rider
 
Get JetBrains Rider
Get your hands on the new features ahead of the release by joining the Early Access Program for Rider 2025.1! Learn more

Code inspection: Use collection's count property

Last modified: 08 April 2024

If a collection has a Count property (or a Length property), JetBrains Rider 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, JetBrains Rider suggests replacing Count() with Length:

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