Bird
Raised Fist0

Identify the error in this LINQ method syntax:

medium📝 Debug Q6 of Q15
C Sharp (C#) - LINQ Fundamentals
Identify the error in this LINQ method syntax:
var numbers = new List<int> {1, 2, 3};
var result = numbers.Select(n => n * 2).Where(n => n > 3);
Console.WriteLine(string.Join(",", result));
AIncorrect lambda syntax in Select
BNo error; code is correct as is
CWhere should come before Select
DCannot chain Select and Where
Step-by-Step Solution
Solution:
  1. Step 1: Check method chaining

    Chaining Select and Where is valid syntax.
  2. Step 2: Check printing of IEnumerable

    string.Join accepts IEnumerable, so no error here.
  3. Step 3: Verify code correctness

    Code runs correctly; no error present.
  4. Final Answer:

    No error; code is correct as is -> Option B
  5. Quick Check:

    Chaining Select and Where is valid [OK]
Quick Trick: Select and Where can chain; IEnumerable works with Join [OK]
Common Mistakes:
MISTAKES
  • Thinking ToList needed before Join
  • Confusing method order
  • Assuming chaining is invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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