Bird
0
0

What will be the output of this C# code?

medium📝 query result Q4 of 15
C Sharp (C#) - Collections
What will be the output of this C# code?
var numbers = new List {1, 2, 3};
numbers.Add(4);
Console.WriteLine(numbers.Count);
A3
B5
C4
DError
Step-by-Step Solution
Solution:
  1. Step 1: Analyze initial list and Add method

    List starts with 3 elements: 1, 2, 3. Add(4) adds one more element.
  2. Step 2: Check Count property after addition

    Count now is 4 because one element was added to the original 3.
  3. Final Answer:

    4 -> Option C
  4. Quick Check:

    Count after Add = 4 [OK]
Quick Trick: Count updates after Add method call [OK]
Common Mistakes:
MISTAKES
  • Assuming Count stays 3
  • Thinking Add replaces elements
  • Expecting runtime error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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