Bird
Raised Fist0

What is the output of the following code?

medium📝 Predict Output Q13 of Q15
C Sharp (C#) - LINQ Fundamentals
What is the output of the following code?
var numbers = new List<int> {1, 2, 3, 4, 5};
var result = numbers.Where(n => n > 3).Select(n => n * 2).ToList();
Console.WriteLine(string.Join(", ", result));
A1, 2, 3, 4, 5
B4, 6, 8, 10
C8, 10
D2, 4, 6, 8, 10
Step-by-Step Solution
Solution:
  1. Step 1: Filter numbers greater than 3

    The Where method selects numbers 4 and 5 from the list.
  2. Step 2: Multiply filtered numbers by 2

    The Select method transforms 4 to 8 and 5 to 10.
  3. Final Answer:

    8, 10 -> Option C
  4. Quick Check:

    Filter >3 then double = 8, 10 [OK]
Quick Trick: Filter first, then transform with Select [OK]
Common Mistakes:
MISTAKES
  • Applying Select before Where (wrong order)
  • Including numbers not greater than 3
  • Printing original list instead of result

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Sharp (C#) Quizzes