Code inspection: Replace with LastOrDefault($args$)
This inspection reports a guarded conditional expression that first checks another condition and then uses Any(...) ? Last(...) : default(T). When the guard is true, the inner Any/Last pair can be simplified to LastOrDefault(...).
Example
var result = isEnabled && items.Any(x => x.IsValid)
? items.Last(x => x.IsValid)
: default(MyType);
var result = isEnabled
? items.LastOrDefault(x => x.IsValid)
: default(MyType);
Quick-fix
Replace the guarded Any(...) ? Last(...) : default(T) pattern with LastOrDefault(...).
29 March 2026