Bird
0
0

What is the output of this code?

medium📝 Predict Output Q13 of 15
C Sharp (C#) - LINQ Fundamentals
What is the output of this code?
var numbers = new[] {1, 2, 3};
var result = from n in numbers select n * 2;
foreach(var r in result) Console.Write(r + " ");
A1 2 3
B3 4 5
C2 4 6
DSyntax error
Step-by-Step Solution
Solution:
  1. Step 1: Understand the select projection

    The query multiplies each number by 2, so 1 becomes 2, 2 becomes 4, 3 becomes 6.
  2. Step 2: Trace the output loop

    The foreach prints each doubled number followed by a space: "2 4 6 "
  3. Final Answer:

    2 4 6 -> Option C
  4. Quick Check:

    Select doubles numbers = 2 4 6 [OK]
Quick Trick: Select transforms each item; multiply 1,2,3 by 2 = 2,4,6 [OK]
Common Mistakes:
MISTAKES
  • Thinking select filters instead of transforms
  • Expecting original numbers
  • Confusing output format

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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