Bird
0
0

Which of the following is the correct syntax for a LINQ query using select to get only the names from a list of Person objects?

easy📝 Syntax Q12 of 15
C Sharp (C#) - LINQ Fundamentals
Which of the following is the correct syntax for a LINQ query using select to get only the names from a list of Person objects?
Avar names = from p in people select p.Name;
Bvar names = from p in people where p.Name;
Cvar names = from p in people orderby p.Name select p;
Dvar names = from p in people group p by p.Name;
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct select syntax

    The correct syntax to project only the Name property is select p.Name.
  2. Step 2: Check other options for errors

    var names = from p in people where p.Name; uses where incorrectly without a condition. var names = from p in people orderby p.Name select p; selects whole object, not just names. var names = from p in people group p by p.Name; groups data, not selects.
  3. Final Answer:

    var names = from p in people select p.Name; -> Option A
  4. Quick Check:

    Select projects properties correctly [OK]
Quick Trick: Select clause syntax: from x in y select x.Property [OK]
Common Mistakes:
MISTAKES
  • Using where without condition
  • Selecting whole object instead of property
  • Confusing group by with select

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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