0
0
C Sharp (C#)programming~20 mins

Verbatim and raw string literals in C Sharp (C#) - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
String Literal Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of verbatim string with escape sequences
What is the output of this C# code snippet?
C Sharp (C#)
string path = @"C:\Users\Admin\Documents";
Console.WriteLine(path);
AC:/Users/Admin/Documents
BC:\\Users\\Admin\\Documents
CC:\Users\Admin\Documents
DC:UsersAdminDocuments
Attempts:
2 left
💡 Hint
Remember that verbatim strings treat backslashes as normal characters.
Predict Output
intermediate
2:00remaining
Output of raw string literal with multiple lines
What will this C# code print?
C Sharp (C#)
string json = """
{
  "name": "Alice",
  "age": 30
}
""";
Console.WriteLine(json);
A
{
  "name": "Alice",
  "age": 30
}
B{ "name": "Alice", "age": 30 }
C{\n \"name\": \"Alice\",\n \"age\": 30\n}
D
{
  name: Alice,
  age: 30
}
Attempts:
2 left
💡 Hint
Raw string literals preserve all whitespace and line breaks exactly.
🔧 Debug
advanced
2:00remaining
Identify the error in verbatim string usage
What error will this code produce?
C Sharp (C#)
string text = @"This is a "quoted" word.";
ASyntaxError: Invalid string literal due to unescaped quotes inside verbatim string
BNo error, prints: This is a "quoted" word.
CCompilation warning: Use double quotes to escape inside verbatim string
DRuntimeException: Unterminated string literal
Attempts:
2 left
💡 Hint
How do you include double quotes inside a verbatim string?
Predict Output
advanced
2:00remaining
Output of raw string literal with embedded quotes
What is the output of this C# code?
C Sharp (C#)
string poem = """""Roses are red,
"Violets" are blue.
""""";
Console.WriteLine(poem);
A
"""Roses are red,
"Violets" are blue.
"""
B
"Roses are red,
"Violets" are blue.
"
C
Roses are red,
Violets are blue.
D
Roses are red,
"Violets" are blue.
Attempts:
2 left
💡 Hint
Raw string literals can contain quotes without escaping if the delimiter count is sufficient.
🧠 Conceptual
expert
2:00remaining
Difference between verbatim and raw string literals
Which statement correctly describes the difference between verbatim (@) and raw (""""" or more quotes) string literals in C#?
ARaw strings require doubling backslashes, verbatim strings do not allow new lines inside.
BVerbatim strings allow escape sequences like \n, raw strings preserve all characters including new lines and quotes without escapes.
CVerbatim strings preserve new lines and quotes without escapes, raw strings require escaping quotes.
DRaw strings are only for single-line strings, verbatim strings are for multiline strings.
Attempts:
2 left
💡 Hint
Think about how each treats backslashes, new lines, and quotes.