miguel velasco
miguel velasco

Reputation: 1

LINQ adding or summing items

I've been trying to find an answer to my question but the wording is difficult.

Let say i have the following:

How could I build a linq query that would tell me how many people are going to each party, so the result would be:

party 1 , 2 people
party 2 , 1 people
party 3 , 2 people

Upvotes: 0

Views: 63

Answers (1)

L.B
L.B

Reputation: 116108

list.GroupBy(x => x.Party)
    .Select(x => new { Party = x.Key, Count = x.Count() });

Upvotes: 5

Related Questions