Complete the code to group numbers by their remainder when divided by 3.
var groups = numbers.[1](n => n % 3);
The GroupBy method groups elements based on a key selector function.
Complete the code to print each group key and its elements.
foreach (var group in groups) { Console.WriteLine($"Key: {group.[1]"); foreach (var num in group) { Console.WriteLine(num); } }
The Key property gives the key value of each group.
Fix the error in the code to group words by their first letter.
var groupedWords = words.[1](w => w[0]);
GroupBy is needed to group elements by a key, here the first letter.
Fill both blanks to create a dictionary from groups with key and count of elements.
var dict = groupedWords.ToDictionary(g => g.[1], g => g.[2]());
Use Key for the dictionary key and Count() to get the number of elements in each group.
Fill all three blanks to group numbers by even/odd and select the key and sum of each group.
var result = numbers.[1](n => n % 2 == 0).Select(g => new { [2] = g.Key, [3] = g.Sum() });
GroupBy groups numbers by even/odd, Key accesses the group key, and Sum calculates the total of each group.