JetBrains Rider 2026.1 Help

代码检查:替换为 OfType<T>().Count()

此检查会报告使用 as 转换元素后再统计非空结果的 LINQ 查询。 可以用 OfType<T>().Count() 更直接地表达相同的计数。

示例

int count = items.Select(x => x as string).Count(y => y != null);
int count = items.OfType<string>().Count();

快速修复

Select(... as T).Count(y => y != null) 模式替换为 OfType<T>().Count()

2026年 5月 8日