Complete the code to immediately execute the LINQ query and get the count of even numbers.
int[] numbers = {1, 2, 3, 4, 5};
int evenCount = numbers.Where(n => n % 2 == 0).[1]();The Count() method immediately executes the query and returns the number of elements that satisfy the condition.
Complete the code to immediately execute the LINQ query and convert the result to a list.
string[] fruits = {"apple", "banana", "cherry"};
var fruitList = fruits.Where(f => f.Contains('a')).[1]();The ToList() method immediately executes the query and returns a List containing the filtered elements.
Fix the error in the code to immediately get the first element that matches the condition.
List<int> scores = new() { 70, 85, 90 };
int topScore = scores.Where(s => s > 80).[1]();The First() method immediately executes the query and returns the first element that matches the condition. It throws an error if no element is found.
Fill both blanks to immediately get the maximum score from the list.
List<int> scores = new() { 55, 78, 92, 88 };
int maxScore = scores.[1](s => s).[2]();OrderByDescending() sorts the scores from highest to lowest, and Max() returns the maximum value immediately.
Fill all three blanks to immediately create a dictionary of words and their lengths for words longer than 3 characters.
string[] words = {"cat", "elephant", "dog", "horse"};
var wordLengths = words.Where(w => w.Length > [1]).ToDictionary([2], [3]);The code filters words longer than 3 characters, then creates a dictionary with the word as the key and its length as the value.