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

Deferred execution behavior 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 create a list of even numbers using deferred execution.

C Sharp (C#)
var numbers = new List<int> {1, 2, 3, 4, 5};
var evens = numbers.Where(n => n [1] 2 == 0);
Drag options to blanks, or click blank then click option'
A*
B/
C%
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using division / instead of modulo % to check even numbers.
2fill in blank
medium

Complete the code to demonstrate deferred execution by modifying the source list after query creation.

C Sharp (C#)
var numbers = new List<int> {1, 2, 3};
var query = numbers.Where(n => n > [1]);
numbers.Add(4);
foreach(var num in query) Console.WriteLine(num);
Drag options to blanks, or click blank then click option'
A1
B3
C2
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a number that excludes the newly added element from the query.
3fill in blank
hard

Fix the error in the code to correctly demonstrate deferred execution with LINQ.

C Sharp (C#)
var list = new List<int> {1, 2, 3};
var result = list.Select(x => x * 2).ToList();
list.Add(4);
var query = list.Select(x => x [1] 2);
foreach(var item in query) Console.WriteLine(item);
Drag options to blanks, or click blank then click option'
A*
B+
C-
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition or division instead of multiplication.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that filters and transforms elements with deferred execution.

C Sharp (C#)
var words = new List<string> {"apple", "bee", "cat", "dog"};
var dict = words.Where(w => w.Length [1] 3)
                .ToDictionary(w => w, w => w.[2]());
Drag options to blanks, or click blank then click option'
A>
BToUpper
C<
DToLower
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operator or string method.
5fill in blank
hard

Fill all three blanks to create a LINQ query that filters, transforms, and orders numbers demonstrating deferred execution.

C Sharp (C#)
var nums = new List<int> {5, 3, 8, 1, 4};
var query = nums.Where(n => n [1] 3)
                .Select(n => n [2] 1)
                .OrderBy(n => n [3] 2);
foreach(var n in query) Console.WriteLine(n);
Drag options to blanks, or click blank then click option'
A>
B+
C*
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong operators causing incorrect filtering or ordering.