ReSharper 2026.1 Help

コードインスペクション:OfType<T>().Count() に置き換え

このインスペクションは、 as を使用して要素をキャストし、null 以外の結果をカウントする 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 年 6 月 12 日