Bird
0
0

Identify the error in this code:

medium📝 Debug Q6 of 15
C Sharp (C#) - Strings and StringBuilder
Identify the error in this code:
var sb = new StringBuilder();
sb.Append("Test");
sb = sb + "ing";
Console.WriteLine(sb.ToString());
ACannot use '+' operator with StringBuilder and string
BMissing semicolon after Append
CStringBuilder cannot be declared with var
DToString method is missing parentheses
Step-by-Step Solution
Solution:
  1. Step 1: Check usage of '+' operator with StringBuilder

    StringBuilder does not support '+' operator with strings directly.
  2. Step 2: Identify correct way to append strings

    Use Append method instead of '+' operator to add strings.
  3. Final Answer:

    Cannot use '+' operator with StringBuilder and string -> Option A
  4. Quick Check:

    StringBuilder '+' operator invalid = Cannot use '+' operator with StringBuilder and string [OK]
Quick Trick: Use Append, not '+' to add strings to StringBuilder [OK]
Common Mistakes:
MISTAKES
  • Trying to concatenate with '+' operator
  • Ignoring method calls for appending
  • Misunderstanding var keyword usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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