from x in myCollection
group x by x.Id into y
select new {
Id = y.Key,
Quantity = y.Sum(x => x.Quantity)
};
How would you write the above as a lambda expression? I’m stuck on the group into part.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Query continuations (select…into and group…into, but not join…into) are equivalent to just splitting up the query expression. So I like to think of your example as:
Change those into dot notation:
Then you could combine them back:
Once you work out what the C# compiler does with query expressions, the rest is relatively straightforward 🙂