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