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

Verbatim and raw string literals in C Sharp (C#) - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a verbatim string literal in C#?
A verbatim string literal starts with @ and allows the string to include backslashes and new lines exactly as typed, without needing escape sequences.
Click to reveal answer
beginner
How do you write a multi-line string in C# using verbatim literals?
Use @ before the opening quote and write the string across multiple lines. For example:
@"Line 1
Line 2"
preserves the line breaks.
Click to reveal answer
intermediate
What is a raw string literal in C# 11 and later?
A raw string literal uses triple quotes ("""), allowing multi-line strings with no escape sequences, preserving all characters exactly as typed.
Click to reveal answer
intermediate
How do you include double quotes inside a verbatim string literal?
Double the double quotes inside the string. For example:
@"She said, ""Hello!"""
outputs: She said, "Hello!"
Click to reveal answer
intermediate
What is the main difference between verbatim and raw string literals in C#?
Verbatim strings start with @ and require doubling quotes to escape them, while raw string literals use triple quotes and allow easier multi-line strings with embedded quotes without doubling.
Click to reveal answer
Which symbol starts a verbatim string literal in C#?
A$
B#
C@
D"""
How do you write a raw string literal in C# 11?
AUse triple double quotes """
BUse @ before the string
CUse single quotes
DUse backticks `
How do you include a double quote inside a verbatim string literal?
ADouble the double quotes ""
BYou cannot include double quotes
CUse single quotes '"'
DEscape with a backslash \"
Which of these is true about raw string literals?
AThey require escaping backslashes
BThey start with @
CThey cannot span multiple lines
DThey preserve all characters exactly as typed
What is the output of this verbatim string? @"C:\Users\Admin"
AC:UsersAdmin
BC:\Users\Admin
CC:/Users/Admin
DError
Explain how verbatim string literals work in C# and how they help with file paths.
Think about how Windows file paths use backslashes.
You got /4 concepts.
    Describe the advantages of raw string literals introduced in C# 11 compared to verbatim strings.
    Consider how raw strings simplify writing complex strings.
    You got /4 concepts.