JetBrains Rider 2026.1 Help

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

此检查会报告使用 as 转换元素并使用 LongCount(...) 统计非 null 结果的 LINQ 查询。 使用 OfType<T>().LongCount() 可以更直接地得到相同的计数。

示例

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

快速修复

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

2026年 5月 8日