84 - LINQ - Group - Aggregate Data

 

There are many ways to group data in a LINQ query, it is one of the most powerful features of LINQ. You can group by a single property, a substring of a property, a computed numeric range, a Boolean predicate, other expressions and a composite key. You can even nest groups within each other and use them as sub queries.

The information or a subset of the information you group can then be stored using objects of a defined class, or you can use anonymous objects.

The group clause is used to group data; it returns a sequence of IGrouping<TKey, TElement> objects. Items that match the group key value, if any, will be stored in the object sequence. The grouping key can be of any type. Let’s say that you have a sequence of Film objects that you want to group on production year, you could then group the LINQ query on the Year property of the elements, which will make year the grouping key. The data type of the grouping key will be inferred by the compiler and the group clauses...

Continue Reading...
Close

50% Complete

Two Step

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.