Bird
0
0

Find the issue in this C# code:

medium📝 Debug Q7 of 15
C Sharp (C#) - Collections
Find the issue in this C# code:
var list = new LinkedList<int>();
list.AddLast(5);
list.RemoveFirst();
list.RemoveFirst();
AAddLast() is not a valid method
BList cannot be empty
CRemoveFirst() does not exist
DRemoving from empty list causes exception
Step-by-Step Solution
Solution:
  1. Step 1: Analyze list operations

    One element (5) is added, then RemoveFirst() removes it, list becomes empty.
  2. Step 2: Check second RemoveFirst()

    Calling RemoveFirst() on empty list throws InvalidOperationException.
  3. Final Answer:

    Removing from empty list causes exception -> Option D
  4. Quick Check:

    RemoveFirst on empty list throws exception [OK]
Quick Trick: Check list not empty before RemoveFirst() [OK]
Common Mistakes:
MISTAKES
  • Assuming RemoveFirst() silently fails
  • Thinking AddLast() is invalid
  • Ignoring exceptions on empty list

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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