max date record in LINQ
Starting from .NET 6 MaxBy LINQ method is available. var result = items.MaxBy(i => i.Date); Prior to .NET 6: O(n log n): var result = items.OrderByDescending(i => i.Date).First(); O(n) – but iterates over the sequence twice: var max = items.Max(i => i.Date); var result = items.First(i => i.Date == max); Or you can use MoreLINQ … Read more