Bird
Raised Fist0

Find the mistake in this C# code:

medium📝 Debug Q7 of Q15
C Sharp (C#) - Collections
Find the mistake in this C# code:
var nums = new List {1, 3, 5};
nums.Sort(x => x);
Console.WriteLine(nums[0]);
ASort method does not take a lambda expression
BList cannot be initialized with values
CConsole.WriteLine syntax is wrong
Dnums[0] is out of range
Step-by-Step Solution
Solution:
  1. Step 1: Check Sort method usage

    Sort() does not accept a lambda like Sort(x => x); it sorts by default or with a Comparison delegate.
  2. Step 2: Validate other code parts

    List initialization and Console.WriteLine are correct; nums[0] is valid index.
  3. Final Answer:

    Sort method does not take a lambda expression -> Option A
  4. Quick Check:

    Sort() no lambda allowed [OK]
Quick Trick: Sort() has no lambda parameter; use Comparison delegate [OK]
Common Mistakes:
MISTAKES
  • Passing lambda directly to Sort
  • Misunderstanding List initialization
  • Incorrect Console.WriteLine usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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