Challenge - 5 Problems
LINQ Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this LINQ method syntax code?
Consider the following C# code using LINQ method syntax. What will be printed to the console?
C Sharp (C#)
var numbers = new List<int> { 1, 2, 3, 4, 5 }; var result = numbers.Where(n => n % 2 == 0).Select(n => n * n); foreach(var num in result) { Console.Write(num + " "); }
Attempts:
2 left
💡 Hint
Think about which numbers are even and what happens to them in the Select step.
✗ Incorrect
The code filters the list to only even numbers (2 and 4), then squares each. So output is 4 and 16.
🧠 Conceptual
intermediate1:30remaining
Which LINQ method syntax expression counts elements greater than 10?
You have a list of integers. Which of the following LINQ method syntax expressions correctly counts how many elements are greater than 10?
Attempts:
2 left
💡 Hint
Count can take a condition directly or you can filter first then count.
✗ Incorrect
Option B uses Count with a predicate, which counts elements matching the condition directly. Option B also works but is less efficient. Option B counts all elements because Select returns booleans. Option B is invalid syntax.
🔧 Debug
advanced2:00remaining
What error does this LINQ method syntax code produce?
Examine the code below. What error will it cause when compiled or run?
C Sharp (C#)
var words = new List<string> { "apple", "banana", "cherry" }; var result = words.Select(word => word.Length > 5 ? word : ); foreach(var w in result) { Console.WriteLine(w); }
Attempts:
2 left
💡 Hint
Look carefully at the ternary operator syntax inside Select.
✗ Incorrect
The ternary operator requires both 'true' and 'false' expressions. Here, the false part is missing, causing a syntax error.
❓ Predict Output
advanced2:30remaining
What is the output of this LINQ method syntax with grouping?
Given the code below, what will be printed to the console?
C Sharp (C#)
var fruits = new List<string> { "apple", "apricot", "banana", "blueberry", "cherry" }; var groups = fruits.GroupBy(f => f[0]); foreach(var group in groups) { Console.Write(group.Key + ":"); Console.WriteLine(string.Join(",", group)); }
Attempts:
2 left
💡 Hint
GroupBy groups by the first letter of each fruit.
✗ Incorrect
The fruits are grouped by their first letter: 'a' group has apple and apricot, 'b' group has banana and blueberry, 'c' group has cherry. The output prints each group key and its items separated by commas.
❓ Predict Output
expert3:00remaining
What is the value of 'result' after this LINQ method syntax chain?
Analyze the code below. What is the value of the variable 'result' after execution?
C Sharp (C#)
var data = new List<int> { 3, 6, 9, 12, 15 }; var result = data.Aggregate(1, (acc, val) => val % 3 == 0 ? acc * val : acc);
Attempts:
2 left
💡 Hint
Aggregate starts with 1 and multiplies values divisible by 3.
✗ Incorrect
All numbers in data are divisible by 3, so the accumulator multiplies all: 1*3=3, 3*6=18, 18*9=162, 162*12=1944, 1944*15=29160.