Less Known LINQ Methods
Introduction LINQ extension methods are pretty cool and they make our lives much easier. They are implemented as .NET extension methods over the Enumerable class in the System.Linq namespace and as usual they all apply to IEnumerable<T> sequences. This time I'll be talking about some LINQ methods that are not so commonly used (as per my understanding). Not sure about you guys, but sometimes I don't even remember that some of these exist. Aggregate/AggregateBy Aggregate applies an accumulator function over a sequence, reducing it to a single value. AggregateBy (.NET 9+) does the same but groups by a key first, producing one accumulated result per key. // Aggregate var product = new[] { 1, 2, 3, 4 }.Aggregate((acc, x) => acc * x); // 24 // AggregateBy var words = new[] { "apple", "ant", "bear", "bee" }; var lengthSums = words.AggregateBy( keySelector: w => w[0], seed: 0, func: (acc, w) => acc + w.Length...