Bird
0
0

Find the issue in this code:

medium📝 Debug Q7 of 15
C Sharp (C#) - LINQ Fundamentals
Find the issue in this code:
var list = new List<string> { "dog", "cat", "bird" };
var sorted = list.OrderByDescending();
AOrderByDescending cannot be used on strings
BOrderByDescending sorts ascending by default
COrderByDescending requires a key selector lambda
DList<string> does not support OrderByDescending
Step-by-Step Solution
Solution:
  1. Step 1: Check method parameters

    OrderByDescending requires a lambda expression to select the key for sorting.
  2. Step 2: Identify missing argument

    The code calls OrderByDescending() without any argument, causing a compile error.
  3. Final Answer:

    OrderByDescending requires a key selector lambda -> Option C
  4. Quick Check:

    OrderByDescending needs a lambda key selector [OK]
Quick Trick: Always provide a key selector lambda to OrderByDescending [OK]
Common Mistakes:
MISTAKES
  • Calling OrderByDescending without parameters
  • Thinking OrderByDescending sorts ascending
  • Assuming strings can't be sorted

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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