Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q6 of 15
C Sharp (C#) - Strings and StringBuilder
Identify the error in this code snippet:
var sb = new System.Text.StringBuilder("Hello");
sb.Remove(3, 10);
Console.WriteLine(sb.ToString());
ARemove method syntax is incorrect
BRemove count exceeds string length causing ArgumentOutOfRangeException
CStringBuilder cannot remove characters
DNo error, code runs fine
Step-by-Step Solution
Solution:
  1. Step 1: Analyze Remove parameters

    String length is 5. Remove(3,10) tries to remove 10 chars starting at index 3, exceeding length.
  2. Step 2: Understand exception thrown

    This causes ArgumentOutOfRangeException because removal range is invalid.
  3. Final Answer:

    Remove count exceeds string length causing ArgumentOutOfRangeException -> Option B
  4. Quick Check:

    Invalid Remove range = ArgumentOutOfRangeException [OK]
Quick Trick: Remove count must not exceed remaining length [OK]
Common Mistakes:
MISTAKES
  • Ignoring string length when removing
  • Assuming Remove silently truncates

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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