How can you create a multi-line string literal in C# that preserves line breaks exactly as typed?
hard🚀 Application Q9 of 15
C Sharp (C#) - Strings and StringBuilder
How can you create a multi-line string literal in C# that preserves line breaks exactly as typed?
AUse normal string with \n escape sequences for new lines
BUse a verbatim string literal with @ and write lines inside quotes
CUse single quotes for multi-line strings
DConcatenate multiple strings with + operator
Step-by-Step Solution
Solution:
Step 1: Understand multi-line string creation
Verbatim strings with @ allow writing multi-line text preserving line breaks.
Step 2: Evaluate options
Use a verbatim string literal with @ and write lines inside quotes correctly uses verbatim strings. Use normal string with \n escape sequences for new lines requires manual \n and does not preserve formatting visually. Use single quotes for multi-line strings is invalid syntax. Concatenate multiple strings with + operator is possible but not preserving literal line breaks in one string.
Final Answer:
Use a verbatim string literal with @ and write lines inside quotes -> Option B
Quick Check:
Multi-line strings = verbatim strings with @ [OK]
Quick Trick:Use @"..." for multi-line strings preserving line breaks [OK]
Common Mistakes:
MISTAKES
Using single quotes for strings
Expecting normal strings to preserve line breaks
Concatenating strings instead of verbatim strings
Master "Strings and StringBuilder" in C Sharp (C#)
9 interactive learning modes - each teaches the same concept differently