9. Groups Flashcards
What does the LINQ GroupBy method do?
Groups the elements of a sequence.
How do you group by elements in a LINQ query expression?
By using the group
and the by
keywords.
eg. group x by x.Field
What are the first two parameters that the GroupBy method takes (apart from the source
)?
- Key Selector
2. Element Selector
What is the elementSelector
parameter used for in a GroupBy method call?
Determining the return type of each element.
How do you define a new variable inside a LINQ query expression?
By using the let
keyword.
eg. let x = new {y.Name};
What is the resultSelector
parameter used for in a GroupBy method call?
Determining the data structure to be returned.
How do you use a result selector in a LINQ GroupBy query expression?
By using the into
keyword after the group/by
clause to define a variable that you use in a select
clause to determine the return type.
What is the keySelector
parameter used for in a GroupBy method call?
Determining what value to group the sequence by. This value also becomes the key of each group element.
What does the SelectMany
extension method do?
It flattens a sequence by allowing us to work with nested sequences.