Bird
Raised Fist0

What will be the output of the following C# code?

medium📝 Predict Output Q4 of Q15
C Sharp (C#) - Strings and StringBuilder
What will be the output of the following C# code?
string s = @"Line1\nLine2";
Console.WriteLine(s);
ALine1 Line2
BLine1 Line2
CLine1\nLine2
DLine1\Line2
Step-by-Step Solution
Solution:
  1. Step 1: Understand verbatim string behavior

    Verbatim strings treat backslashes as literal characters, so \n is not a newline but two characters: backslash and n.
  2. Step 2: Predict output of Console.WriteLine

    The string prints exactly as written: Line1\nLine2 (with backslash and n visible).
  3. Final Answer:

    Line1\nLine2 -> Option C
  4. Quick Check:

    Verbatim string prints backslash literally = Line1\nLine2 [OK]
Quick Trick: Verbatim strings print backslashes literally [OK]
Common Mistakes:
MISTAKES
  • Expecting \n to create newline in verbatim strings
  • Confusing verbatim and normal strings
  • Assuming escape sequences work in verbatim strings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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