Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to select all numbers from the list.
C Sharp (C#)
var numbers = new List<int> {1, 2, 3, 4, 5};
var query = from num in numbers select [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the collection name instead of the iteration variable.
Using a variable name not defined in the query.
✗ Incorrect
In LINQ query syntax, you select the variable defined in the from clause, here 'num'.
2fill in blank
mediumComplete the code to filter numbers greater than 3.
C Sharp (C#)
var numbers = new List<int> {1, 2, 3, 4, 5};
var query = from num in numbers where num [1] 3 select num; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>'.
Using '==' which only selects numbers equal to 3.
✗ Incorrect
To filter numbers greater than 3, use the '>' operator in the where clause.
3fill in blank
hardFix the error in the LINQ query to order numbers ascending.
C Sharp (C#)
var numbers = new List<int> {5, 3, 1, 4, 2};
var query = from num in numbers orderby num [1] select num; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'descending', which orders from highest to lowest.
Using invalid shorthands like 'asc' or 'ascend'.
✗ Incorrect
In C# LINQ query syntax, use 'ascending' after 'orderby' to explicitly order ascending (this is the default behavior).
4fill in blank
hardFill both blanks to select names starting with 'A' and order them descending.
C Sharp (C#)
var names = new List<string> {"Alice", "Bob", "Anna", "Mike"};
var query = from name in names where name.StartsWith([1]) orderby name [2] select name; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'a' which misses uppercase names.
Using 'ascending' instead of 'descending' for order.
✗ Incorrect
To select names starting with uppercase 'A', use "A" and order descending with 'descending'.
5fill in blank
hardFill all three blanks to select even numbers, order ascending, and select their squares.
C Sharp (C#)
var numbers = new List<int> {1, 2, 3, 4, 5};
var query = from num in numbers where num [1] 2 == 0 orderby num [2] select num * [3]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong operator like '+' or '-' for even check.
Using 'descending' instead of 'ascending'.
Using incorrect value like '2' instead of 'num' for squaring.
✗ Incorrect
Use '%' to check even numbers (num % 2 == 0), 'ascending' to order ascending, and 'num' to select squares (num * num).