Bird
Raised Fist0

What will be the output of this code?

medium📝 Predict Output Q5 of Q15
C Sharp (C#) - Strings and StringBuilder
What will be the output of this code?
string result = "Start" + null + "End";
Console.WriteLine(result);
ANullReferenceException
BStartnullEnd
CStart End
DStartEnd
Step-by-Step Solution
Solution:
  1. Step 1: Understand concatenation with null

    In C#, concatenating a string with null treats null as an empty string.
  2. Step 2: Result of concatenation

    "Start" + null + "End" becomes "Start" + "" + "End" which is "StartEnd".
  3. Final Answer:

    StartEnd -> Option D
  4. Quick Check:

    Concatenating null string treats it as empty [OK]
Quick Trick: Null strings concatenate as empty strings [OK]
Common Mistakes:
MISTAKES
  • Expecting 'null' text in output
  • Assuming space added automatically
  • Thinking it throws exception

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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