Bird
0
0

Which of the following is the correct syntax to order a list of Person objects by their Age property in ascending order using LINQ?

easy📝 Syntax Q3 of 15
C Sharp (C#) - LINQ Fundamentals
Which of the following is the correct syntax to order a list of Person objects by their Age property in ascending order using LINQ?
Apeople.OrderBy(p => p.Age);
Bpeople.OrderBy(p => p.Name);
Cpeople.Where(p => p.Age);
Dpeople.Select(p => p.Age);
Step-by-Step Solution
Solution:
  1. Step 1: Identify method to sort by property

    OrderBy sorts elements by a key selector, here p => p.Age.
  2. Step 2: Check syntax correctness

    people.OrderBy(p => p.Age); correctly orders by age ascending.
  3. Final Answer:

    people.OrderBy(p => p.Age); -> Option A
  4. Quick Check:

    LINQ OrderBy = Sort ascending [OK]
Quick Trick: Use OrderBy with a property selector to sort ascending [OK]
Common Mistakes:
MISTAKES
  • Using Where to sort
  • Ordering by wrong property
  • Missing lambda syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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