0
0
C Sharp (C#)programming~10 mins

LINQ method syntax in C Sharp (C#) - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to select all even numbers from the list using LINQ method syntax.

C Sharp (C#)
var evens = numbers.Where(n => n [1] 2 == 0).ToList();
Drag options to blanks, or click blank then click option'
A%
B/
C*
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using division operator '/' instead of modulo '%'.
Using multiplication '*' or addition '+' operators incorrectly.
2fill in blank
medium

Complete the code to order the list of names alphabetically using LINQ method syntax.

C Sharp (C#)
var sortedNames = names.[1](name => name);
Drag options to blanks, or click blank then click option'
AGroupBy
BWhere
CSelect
DOrderBy
Attempts:
3 left
💡 Hint
Common Mistakes
Using Where which filters instead of sorting.
Using Select which projects elements.
Using GroupBy which groups elements.
3fill in blank
hard

Fix the error in the code to find the first number greater than 10 using LINQ method syntax.

C Sharp (C#)
var first = numbers.[1](n => n > 10);
Drag options to blanks, or click blank then click option'
AFirstOrDefault
BOrderBy
CSelect
DWhere
Attempts:
3 left
💡 Hint
Common Mistakes
Using Where which returns a collection, not a single element.
Using Select which projects elements.
Using OrderBy which sorts elements.
4fill in blank
hard

Fill both blanks to create a dictionary from a list of words where the key is the word and the value is its length.

C Sharp (C#)
var wordLengths = words.ToDictionary([1] => [1], [2] => [2].Length);
Drag options to blanks, or click blank then click option'
Aword
Bw
Citem
Dx
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.
Using variable names not matching in both selectors.
5fill in blank
hard

Fill all three blanks to filter numbers greater than 5, order them descending by their squares.

C Sharp (C#)
var result = numbers.Where([1] => [1] [2] 5).OrderByDescending([3] => [3] * [3]).ToList();
Drag options to blanks, or click blank then click option'
An
B>
Cx
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' for filtering.
Mixing variable names between lambdas.
Not squaring the number in the ordering.