From the course: .NET Essentials: Working with LINQ

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

GroupBy with ResultSelector

GroupBy with ResultSelector - .NET Tutorial

From the course: .NET Essentials: Working with LINQ

GroupBy with ResultSelector

- [Instructor] One of the principles of using GroupBy is that you get the sequence of groups. And one of the principles of groups is that they have a key and a value. The key represents the item that you created the group on, or how you split it into groups. And the value is all of the items that are in that group. Refresh your memory? There's the key and there's the value. There's nine items in this group here and there is 10 items in this group. We've seen this many times. The problem with this is that if you want to work with the items in their group, it's called key and value, and you might want to rename those with a more representative name To do that we can use something called the GroupBy selector. I'm using it as the third argument here in the GroupBy call. So again, keySelector color family, elementSelector is this anonymous type, and then resultSelector expects a lambda with the key passed in as the first…

Contents