Bird
0
0

Examine the following C# code snippet and identify the problem:

medium📝 Debug Q7 of 15
C Sharp (C#) - Collections
Examine the following C# code snippet and identify the problem:
int[] numbers = new int[3];
numbers.Add(10);
Console.WriteLine(numbers.Length);
AArray length cannot be printed
BArrays do not have an Add method
CArray size is too small to hold 10
DAdd method requires a second parameter
Step-by-Step Solution
Solution:
  1. Step 1: Check array methods

    Arrays in C# do not have an Add method; this is a method of collections like List<T>.
  2. Step 2: Understand array length

    Array length can be printed using the Length property without issue.
  3. Final Answer:

    Arrays do not have an Add method -> Option B
  4. Quick Check:

    Arrays lack Add method [OK]
Quick Trick: Arrays lack Add method; use List for adding [OK]
Common Mistakes:
MISTAKES
  • Assuming arrays have Add method
  • Confusing array length with capacity

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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