Challenge - 5 Problems
Immediate Execution Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of Count() on a filtered list
What is the output of this C# code using LINQ's immediate execution method Count()?
C Sharp (C#)
using System; using System.Linq; class Program { static void Main() { int[] numbers = {1, 2, 3, 4, 5}; int count = numbers.Where(n => n > 3).Count(); Console.WriteLine(count); } }
Attempts:
2 left
💡 Hint
Count() returns how many items match the condition immediately.
✗ Incorrect
The Where clause filters numbers greater than 3: 4 and 5. Count() returns 2 immediately.
❓ Predict Output
intermediate2:00remaining
Result of ToList() on a query
What will be printed by this C# program using ToList() for immediate execution?
C Sharp (C#)
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main() { var words = new List<string> {"apple", "banana", "cherry"}; var filtered = words.Where(w => w.Contains('a')).ToList(); Console.WriteLine(filtered.Count); } }
Attempts:
2 left
💡 Hint
ToList() creates a list immediately with all matching items.
✗ Incorrect
Words containing 'a' are "apple" and "banana", so filtered list has 2 items.
❓ Predict Output
advanced2:00remaining
Output of First() with condition
What does this C# code print when using First() as an immediate execution method?
C Sharp (C#)
using System; using System.Linq; class Program { static void Main() { int[] nums = {10, 20, 30, 40}; int first = nums.Where(n => n > 15).First(); Console.WriteLine(first); } }
Attempts:
2 left
💡 Hint
First() returns the first element that matches the condition immediately.
✗ Incorrect
Numbers greater than 15 are 20, 30, 40. First() returns 20.
❓ Predict Output
advanced2:00remaining
Output of Single() with one matching element
What will this C# program print using Single() as an immediate execution method?
C Sharp (C#)
using System; using System.Linq; class Program { static void Main() { int[] values = {5, 10, 15}; int single = values.Single(v => v == 10); Console.WriteLine(single); } }
Attempts:
2 left
💡 Hint
Single() returns the only element matching the condition or throws if none or multiple.
✗ Incorrect
Only 10 matches v == 10, so Single() returns 10.
❓ Predict Output
expert2:00remaining
Output of Count() after modifying source collection
What is the output of this C# program that uses Count() immediate execution after modifying the source array?
C Sharp (C#)
using System; using System.Linq; class Program { static void Main() { int[] data = {1, 2, 3, 4}; var query = data.Where(x => x > 2); data[2] = 10; // change 3 to 10 int count = query.Count(); Console.WriteLine(count); } }
Attempts:
2 left
💡 Hint
Count() evaluates the query immediately using the current state of the data.
✗ Incorrect
After changing data[2] to 10, elements > 2 are 10 and 4, so count is 2.