From the course: Complete Guide to .NET LINQ: Querying Collections, Databases, and Markup

Unlock this course with a free trial

Join today to access over 24,700 courses taught by industry experts.

Renaming keys/values with query expressions

Renaming keys/values with query expressions

- [Instructor] Let's see how to use a result selector in a query expression. You can see here in the bottom half of LINQPad that it's working similar to the previous example. I've got my family column and I've got my colors column. So what is different? Well, the first three lines are the same. I'm grouping into the color short, and that gives me the anonymous type for this subsequence. What we need to do next is when we do our group, we're going to group into another variable, so you can think of into as similar to the let keyword. Up here, it created a temporary variable that I used from my anonymous type. On line 8 it's creating a temporary variable that represents the group that I will use in my select at the end of this query expression. Remember that when you have a query expression, it ends with either select or group. I have this temporary variable on line 8. So now on line 10 I can say I want to select out a new anonymous type, and I'm changing the family group's key to…

Contents