Code inspection: Replace with LastOrDefault($args$)
This inspection reports a conditional expression that checks Any(...) before calling Last(...), and returns null when there is no match. That pattern is equivalent to LastOrDefault(...).
Example
var result = items.Any(x => x.IsValid) ? items.Last(x => x.IsValid) : null;
var result = items.LastOrDefault(x => x.IsValid);
Quick-fix
Replace the Any(...) ? Last(...) : null pattern with LastOrDefault(...).
29 March 2026