Bird
0
0

Find the issue in this code:

medium📝 Debug Q7 of 15
C Sharp (C#) - Strings and StringBuilder
Find the issue in this code:
var sb = new System.Text.StringBuilder();
sb.Insert(0, "Start");
sb.Append(null);
Console.WriteLine(sb.ToString());
AAppending null throws ArgumentNullException
BAppending null appends empty string without error
CInsert at index 0 is invalid
DStringBuilder cannot be empty initially
Step-by-Step Solution
Solution:
  1. Step 1: Check Insert and Append behavior

    Insert at index 0 is valid on empty StringBuilder. Appending null appends empty string silently.
  2. Step 2: Confirm no exceptions thrown

    Appending null does not throw error; it is treated as empty string.
  3. Final Answer:

    Appending null appends empty string without error -> Option B
  4. Quick Check:

    Append(null) = empty string append [OK]
Quick Trick: Append(null) adds nothing, no error [OK]
Common Mistakes:
MISTAKES
  • Expecting exception on Append(null)
  • Thinking Insert(0, ...) invalid on empty

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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