Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a list of integers.
C Sharp (C#)
List<int> numbers = new List<int> [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets instead of parentheses.
Using curly braces without initialization.
✗ Incorrect
The correct syntax to create a new list in C# uses parentheses () after the constructor.
2fill in blank
mediumComplete the code to filter numbers greater than 5 using LINQ.
C Sharp (C#)
var filtered = numbers.Where(n => n [1] 5);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using less than operator instead of greater than.
Using equality operator which filters only numbers equal to 5.
✗ Incorrect
The Where method filters elements. To get numbers greater than 5, use the greater than operator >.
3fill in blank
hardFix the error in the LINQ query to select names starting with 'A'.
C Sharp (C#)
var result = names.Where(name => name.[1]("A"));
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect casing for method name.
Misspelling the method name.
✗ Incorrect
The correct method name is StartsWith with capital S and W.
4fill in blank
hardFill both blanks to create a dictionary from a list using LINQ.
C Sharp (C#)
var dict = people.ToDictionary([1] => [2].Id);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in the lambda expression.
Using variable names not declared in the lambda.
✗ Incorrect
In the lambda expression, the variable name must be consistent. Here, p is used both times.
5fill in blank
hardFill all three blanks to select and order names using LINQ.
C Sharp (C#)
var orderedNames = people.Select([1] => [2].Name).OrderBy([3] => [3]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in the two lambda expressions.
Using variable names that are not declared.
✗ Incorrect
Use p as the variable in Select and OrderBy for clarity and consistency.