Bird
Raised Fist0

What does the OrderBy method return when applied to a collection in C#?

easy🧠 Conceptual Q1 of Q15
C Sharp (C#) - LINQ Fundamentals
What does the OrderBy method return when applied to a collection in C#?
AA new collection sorted in ascending order
BThe original collection sorted in place
CA collection sorted in descending order
DA collection filtered by a condition
Step-by-Step Solution
Solution:
  1. Step 1: Understand the behavior of OrderBy

    The OrderBy method creates a new sorted sequence without modifying the original collection.
  2. Step 2: Identify the sorting order

    By default, OrderBy sorts elements in ascending order.
  3. Final Answer:

    A new collection sorted in ascending order -> Option A
  4. Quick Check:

    OrderBy returns a sorted new collection [OK]
Quick Trick: OrderBy returns a new sorted sequence, original stays unchanged [OK]
Common Mistakes:
MISTAKES
  • Thinking OrderBy sorts the original collection in place
  • Confusing OrderBy with OrderByDescending
  • Assuming OrderBy filters elements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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