Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q6 of 15
C Sharp (C#) - Strings and StringBuilder
Identify the error in this code snippet:
string s = "Hello";
s = s + 10.5;
Console.WriteLine(s);
AOutputs Hello10
BCompile error due to double concatenation
CRuntime error due to type mismatch
DNo error, outputs Hello10.5
Step-by-Step Solution
Solution:
  1. Step 1: Check concatenation of string and double

    C# converts the double 10.5 to string "10.5" automatically when concatenated with a string.
  2. Step 2: Result of concatenation

    The string becomes "Hello10.5" and prints without error.
  3. Final Answer:

    No error, outputs Hello10.5 -> Option D
  4. Quick Check:

    String + double converts double to string [OK]
Quick Trick: Numbers convert to strings automatically in concatenation [OK]
Common Mistakes:
MISTAKES
  • Expecting compile or runtime error
  • Assuming double truncates to int
  • Thinking output is Hello10

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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