Bird
0
0

What is the output of this C# code?

medium📝 Predict Output Q4 of 15
C Sharp (C#) - Strings and StringBuilder
What is the output of this C# code?
string s = "Hi";
s += 5;
Console.WriteLine(s);
AHi
B10
CHi5
DCompile error
Step-by-Step Solution
Solution:
  1. Step 1: Understand += operator with string and int

    The += operator concatenates the string with the string representation of the integer 5.
  2. Step 2: Result of concatenation

    The string "Hi" becomes "Hi5" after concatenation.
  3. Final Answer:

    Hi5 -> Option C
  4. Quick Check:

    String += int converts int to string and concatenates [OK]
Quick Trick: += concatenates strings and converts numbers automatically [OK]
Common Mistakes:
MISTAKES
  • Expecting numeric addition
  • Thinking it prints original string only
  • Assuming compile error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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