Complete the code to select all even numbers from the list using LINQ method syntax.
var evens = numbers.Where(n => n [1] 2 == 0).ToList();
The modulo operator % returns the remainder. To find even numbers, we check if n % 2 == 0.
Complete the code to order the list of names alphabetically using LINQ method syntax.
var sortedNames = names.[1](name => name);Where which filters instead of sorting.Select which projects elements.GroupBy which groups elements.The OrderBy method sorts elements in ascending order based on a key.
Fix the error in the code to find the first number greater than 10 using LINQ method syntax.
var first = numbers.[1](n => n > 10);
Where which returns a collection, not a single element.Select which projects elements.OrderBy which sorts elements.FirstOrDefault returns the first element matching the condition or default if none found. Where returns a collection, not a single element.
Fill both blanks to create a dictionary from a list of words where the key is the word and the value is its length.
var wordLengths = words.ToDictionary([1] => [1], [2] => [2].Length);
We use the same variable name word for both key and value selector functions.
Fill all three blanks to filter numbers greater than 5, order them descending by their squares.
var result = numbers.Where([1] => [1] [2] 5).OrderByDescending([3] => [3] * [3]).ToList();
We filter numbers greater than 5 using n > 5, then order descending by their squares using x => x * x.