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

LINQ query 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 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'
Anum
Bnumbers
Cnumber
Dn
Attempts:
3 left
💡 Hint
Common Mistakes
Using the collection name instead of the iteration variable.
Using a variable name not defined in the query.
2fill in blank
medium

Complete 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'
A<=
B==
C<
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>'.
Using '==' which only selects numbers equal to 3.
3fill in blank
hard

Fix 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'
Adescending
Basc
Cascending
Dascend
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'descending', which orders from highest to lowest.
Using invalid shorthands like 'asc' or 'ascend'.
4fill in blank
hard

Fill 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'
A"A"
B"a"
Cascending
Ddescending
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'a' which misses uppercase names.
Using 'ascending' instead of 'descending' for order.
5fill in blank
hard

Fill 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'
A%
Bascending
Cnum
D-
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.