JetBrains Rider 2026.1 Help

Code inspection: Replace with FirstOrDefault($args$)

This inspection reports a guarded conditional expression that first checks another condition and then uses Any(...) ? First(...) : default(T). 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) : default(MyType);
var result = isEnabled ? items.FirstOrDefault(x => x.IsValid) : default(MyType);

Quick-fix

Replace the guarded Any(...) ? First(...) : default(T) pattern with FirstOrDefault(...).

29 March 2026