JetBrains Rider 2026.1 Help

Code inspection: Replace with single call to LastOrDefault(..)

This inspection reports a LINQ query that filters with Where(...) and then immediately calls LastOrDefault(). The same query is shorter and clearer as a single LastOrDefault(...) call.

Example

var item = items.Where(x => x.IsActive).LastOrDefault();
var item = items.LastOrDefault(x => x.IsActive);

Quick-fix

Replace the Where(...).LastOrDefault() chain with LastOrDefault(...).

29 March 2026