JetBrains Rider 2026.1 Help

Code inspection: Replace with OfType<T>().Any()

This inspection reports a LINQ query that casts elements with as and then uses Any(...) only to check whether any cast succeeded. The same result is clearer with OfType<T>().Any().

Example

bool hasStrings = items.Select(x => x as string).Any(y => y != null);
bool hasStrings = items.OfType<string>().Any();

Quick-fix

Replace the Select(... as T).Any(y => y != null) pattern with OfType<T>().Any().

29 March 2026