ReSharper 2025.2 Help

代码检查:使用集合的 count 属性

如果集合具有 Count 属性(或 Length 属性),ReSharper 建议使用该属性而不是 Count() 方法。 该属性的运行速度更快(要了解原因,请阅读下面 另请参阅 中链接的 StackOverflow 答案)。 此类替换仅适用于实现 ICollection<T> 或其派生接口的集合。

对于数组,ReSharper 建议将 Count() 替换为 Length

public int BooksCount(string[] books) { return books.Count(); }
public int BooksCount(string[] books) { return books.Length; }

对于其他集合类型,ReSharper 建议将 Count() 替换为 Count

public int ToysCount(IList<string> toys) { return toys.Count(); }
public int ToysCount(IList<string> toys) { return toys.Count; }
最后修改日期: 2025年 9月 27日