Bird
0
0

What will this C# code print?

medium📝 Predict Output Q5 of 15
C Sharp (C#) - Strings and StringBuilder
What will this C# code print?
string multiLine = @"Line1
Line2";
string rawMulti = """Line1
Line2""";
Console.WriteLine(multiLine.Length == rawMulti.Length);
AFalse
BRuntime exception
CCompilation error
DTrue
Step-by-Step Solution
Solution:
  1. Step 1: Analyze multiLine string content

    multiLine is verbatim string with literal \n characters, so length counts backslash and n as two chars.
  2. Step 2: Analyze rawMulti string content

    rawMulti is raw string with actual newline character, so length counts newline as one char.
  3. Step 3: Compare lengths

    Lengths differ because verbatim string has two chars for \n, raw string has one newline char.
  4. Final Answer:

    False -> Option A
  5. Quick Check:

    Verbatim \n vs raw newline length differs = false [OK]
Quick Trick: Verbatim \n is two chars; raw string newline is one char [OK]
Common Mistakes:
MISTAKES
  • Assuming verbatim \n is newline character
  • Thinking lengths are equal
  • Confusing raw string newlines with escape sequences

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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