代码检查:替换为 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日