Bird
Raised Fist0

What will be the output of this C# code?

medium📝 Predict Output Q5 of Q15
C Sharp (C#) - Collections
What will be the output of this C# code?
var list = new LinkedList<int>();
list.AddLast(10);
list.AddLast(20);
list.AddLast(30);
list.Remove(20);
Console.WriteLine(list.Count);
A3
B2
C1
D0
Step-by-Step Solution
Solution:
  1. Step 1: Add three elements

    Elements 10, 20, 30 are added, so count is 3 initially.
  2. Step 2: Remove element 20

    Removing 20 reduces count by 1, so count becomes 2.
  3. Final Answer:

    2 -> Option B
  4. Quick Check:

    Count after removal = 2 [OK]
Quick Trick: Remove() decreases count if element exists [OK]
Common Mistakes:
MISTAKES
  • Assuming Remove() removes by index
  • Forgetting to update count after removal
  • Expecting count to remain 3

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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