From the course: .NET Essentials: Working with LINQ

Unlock this course with a free trial

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

GroupBy with ElementSelector

GroupBy with ElementSelector - .NET Tutorial

From the course: .NET Essentials: Working with LINQ

GroupBy with ElementSelector

- [Instructor] I'm looking at a previous example. This is where I use the group by extension method. And I provided the key to create the group here with the color family. So, remember what happens when I run this? I get 11 items in the sequence, 11 groups in the sequence. And when I look at one of the groups, like here I'm looking at the group that has the key red, I'm seeing there are nine items in that group. And I see all of the properties on that web color type. Now, I sometimes call these columns when I'm using LINQPad, because LINQPad puts them in columns. But, of course, they're properties of the web color class. There are times when you don't want to see all these properties, and we've seen this in some of the other examples we've looked at where we use an anonymous type to project out a new type with just the columns that we want. So, there's a way to do this using the group by extension method. It is called the…

Contents