Bird
0
0

Which of the following is the correct syntax to select the square of each number from an integer array numbers using LINQ?

easy📝 Syntax Q3 of 15
C Sharp (C#) - LINQ Fundamentals
Which of the following is the correct syntax to select the square of each number from an integer array numbers using LINQ?
Avar result = from n in numbers group n * n by n;
Bvar result = from n in numbers where n * n;
Cvar result = from n in numbers select n + n;
Dvar result = from n in numbers select n * n;
Step-by-Step Solution
Solution:
  1. Step 1: Understand projection of transformed data

    The select clause can project transformed values, here n * n for square.
  2. Step 2: Verify syntax correctness

    where is for filtering, not projection; group by groups data; select n + n projects double, not square.
  3. Final Answer:

    var result = from n in numbers select n * n; -> Option D
  4. Quick Check:

    Select projects transformed values [OK]
Quick Trick: Select projects expressions, where filters [OK]
Common Mistakes:
MISTAKES
  • Using where for projection
  • Selecting wrong expression
  • Misusing group by for projection

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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