Bird
Raised Fist0

What will be the output of this C# code?

medium📝 Predict Output Q4 of Q15
C Sharp (C#) - Strings and StringBuilder
What will be the output of this C# code?
var sb = new StringBuilder();
sb.Append("Hello");
sb.Append(" World");
Console.WriteLine(sb.ToString());
AHello World
BHelloWorld
CdlroW olleH
DHello
Step-by-Step Solution
Solution:
  1. Step 1: Understand Append method behavior

    Append adds the string exactly as given without extra spaces.
  2. Step 2: Analyze the appended strings

    First "Hello", then " World" (with space), so combined is "Hello World".
  3. Final Answer:

    Hello World -> Option A
  4. Quick Check:

    Append adds strings as-is = "Hello World" [OK]
Quick Trick: Append adds strings exactly as given [OK]
Common Mistakes:
MISTAKES
  • Assuming Append adds no spaces
  • Thinking Append adds extra spaces
  • Confusing ToString output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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