Bird
0
0

What is the output of the following C# code?

medium📝 Predict Output Q13 of 15
C Sharp (C#) - Strings and StringBuilder
What is the output of the following C# code?
string s = "Line1\nLine2";
Console.WriteLine(s);
ALine1\nLine2
BLine1\n\nLine2
CLine1 Line2
DLine1 Line2
Step-by-Step Solution
Solution:
  1. Step 1: Understand escape sequences in strings

    The sequence \n represents a newline character in C# strings.
  2. Step 2: Predict output of Console.WriteLine

    The string "Line1\nLine2" will print as two lines: "Line1" on the first line and "Line2" on the second line.
  3. Final Answer:

    Line1 Line2 -> Option C
  4. Quick Check:

    \n creates new line = D [OK]
Quick Trick: Escape \n prints new line in output [OK]
Common Mistakes:
MISTAKES
  • Printing \n literally instead of new line
  • Confusing verbatim strings with normal strings
  • Expecting spaces instead of new lines

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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