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

Immediate execution methods 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 immediately execute the LINQ query and get the count of even numbers.

C Sharp (C#)
int[] numbers = {1, 2, 3, 4, 5};
int evenCount = numbers.Where(n => n % 2 == 0).[1]();
Drag options to blanks, or click blank then click option'
ASelect
BCount
CWhere
DOrderBy
Attempts:
3 left
💡 Hint
Common Mistakes
Using Select() instead of Count(), which does not return a count.
Using Where() again, which just filters but does not execute.
2fill in blank
medium

Complete the code to immediately execute the LINQ query and convert the result to a list.

C Sharp (C#)
string[] fruits = {"apple", "banana", "cherry"};
var fruitList = fruits.Where(f => f.Contains('a')).[1]();
Drag options to blanks, or click blank then click option'
AToArray
BOrderBy
CSelect
DToList
Attempts:
3 left
💡 Hint
Common Mistakes
Using ToArray() which returns an array, not a List.
Using Select() which does not execute the query immediately.
3fill in blank
hard

Fix the error in the code to immediately get the first element that matches the condition.

C Sharp (C#)
List<int> scores = new() { 70, 85, 90 };
int topScore = scores.Where(s => s > 80).[1]();
Drag options to blanks, or click blank then click option'
AFirst
BFirstOrDefault
CSingle
DLast
Attempts:
3 left
💡 Hint
Common Mistakes
Using Single() which expects exactly one element.
Using Last() which returns the last matching element.
4fill in blank
hard

Fill both blanks to immediately get the maximum score from the list.

C Sharp (C#)
List<int> scores = new() { 55, 78, 92, 88 };
int maxScore = scores.[1](s => s).[2]();
Drag options to blanks, or click blank then click option'
AMax
BMin
COrderByDescending
DOrderBy
Attempts:
3 left
💡 Hint
Common Mistakes
Using Min() instead of Max().
Using OrderBy() which sorts ascending.
5fill in blank
hard

Fill all three blanks to immediately create a dictionary of words and their lengths for words longer than 3 characters.

C Sharp (C#)
string[] words = {"cat", "elephant", "dog", "horse"};
var wordLengths = words.Where(w => w.Length > [1]).ToDictionary([2], [3]);
Drag options to blanks, or click blank then click option'
A3
Bw
Cw.Length
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Using 4 instead of 3 for the length filter.
Using incorrect key or value selectors in ToDictionary().