Code inspection: Replace with OfType<T>().First()
This inspection reports a LINQ query that casts elements with as and then uses First(...) to find the first non-null cast result. The same intent is clearer with OfType<T>().First().
Example
var first = items.Select(x => x as string).First(y => y != null);
var first = items.OfType<string>().First();
Quick-fix
Replace the Select(... as T).First(y => y != null) pattern with OfType<T>().First().
29 March 2026