Bird
0
0

What will be the output of this C# code?

medium📝 Predict Output Q13 of 15
C Sharp (C#) - Strings and StringBuilder
What will be the output of this C# code?
var sb = new StringBuilder();
sb.Append("Hi");
sb.Append(" there");
Console.WriteLine(sb.ToString());
AHi there
BHi
C there
DHi\n there
Step-by-Step Solution
Solution:
  1. Step 1: Understand Append method behavior

    Append adds text to the existing StringBuilder content without spaces unless added explicitly.
  2. Step 2: Trace the code execution

    First Append adds "Hi", second adds " there" (with space), so combined string is "Hi there".
  3. Final Answer:

    Hi there -> Option A
  4. Quick Check:

    Appending strings combines them exactly = D [OK]
Quick Trick: Append joins text exactly as given, watch spaces [OK]
Common Mistakes:
MISTAKES
  • Assuming Append adds spaces automatically
  • Expecting only first Append output
  • Confusing newline characters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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