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