Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is a string literal in C#?
A string literal is a sequence of characters enclosed in double quotes, like "Hello". It represents a fixed string value in the code.
Click to reveal answer
beginner
How do you create a verbatim string literal in C#?
By prefixing the string with @, like @"C:\Users\Name". It treats backslashes and newlines as literal characters without needing escape sequences.
Click to reveal answer
intermediate
What is the difference between a regular string literal and a verbatim string literal?
Regular string literals use escape sequences (like \n for newline). Verbatim string literals (with @) treat the string exactly as typed, including backslashes and newlines.
Click to reveal answer
intermediate
Can you use double quotes inside a verbatim string literal? How?
Yes, by doubling the double quotes inside the string. For example: @"She said, ""Hello""." represents She said, "Hello".
Click to reveal answer
beginner
What type does a string literal have in C#?
A string literal has the type System.String, which is an alias for the keyword string in C#.
Click to reveal answer
Which of the following is a valid verbatim string literal in C#?
A@"C:\Program Files\App"
B"C:\Program Files\App"
C'C:\Program Files\App'
D"C:/Program Files/App"
✗ Incorrect
Option A uses @ to create a verbatim string literal, so backslashes are treated literally without needing double escaping.
How do you represent a newline character in a regular string literal?
A\n
B@n
C\newline
Dnewline
✗ Incorrect
In regular string literals, \n is the escape sequence for a newline character.
What happens if you write @"Hello "World"" in C#?
AString with embedded quotes
BString with newline
CString with backslashes
DCompilation error due to unescaped quotes
✗ Incorrect
Double quotes inside a verbatim string must be doubled to escape them. Writing @"Hello "World"" causes a compilation error.
Which keyword is an alias for System.String in C#?
Atext
Bstring
CStringLiteral
Dstr
✗ Incorrect
The keyword string is an alias for System.String in C#.
Which of these is NOT a valid way to create a string in C#?
Astring s = "Hello";
Bstring s = @"Hello";
Cstring s = 'Hello';
Dstring s = new string(new char[] {'H','e','l','l','o'});
✗ Incorrect
Single quotes are for char literals, not strings. So 'Hello' is invalid for a string.
Explain how to create and use verbatim string literals in C# and why they are useful.
Think about file paths and multiline text.
You got /4 concepts.
Describe the difference between regular string literals and verbatim string literals in C#.
Consider how newlines and backslashes are handled.
You got /3 concepts.
Practice
(1/5)
1. Which of the following correctly creates a string literal in C#?
easy
A. string s = `Hello World`;
B. string s = 'Hello World';
C. string s = Hello World;
D. string s = "Hello World";
Solution
Step 1: Understand string literal syntax in C#
Strings in C# must be enclosed in double quotes (").
Step 2: Check each option for correct syntax
string s = "Hello World"; uses double quotes correctly. string s = 'Hello World'; uses single quotes which are for characters, not strings. string s = Hello World; has no quotes, so it's invalid. string s = `Hello World`; uses backticks which are not valid string delimiters in C#.
Final Answer:
string s = "Hello World"; -> Option D
Quick Check:
Strings use double quotes = A [OK]
Hint: Strings always use double quotes in C# [OK]
Common Mistakes:
Using single quotes for strings
Omitting quotes around text
Using backticks instead of quotes
2. Which of the following is the correct way to create a verbatim string literal in C#?
easy
A. string path = @"C:\Users\Admin";
B. string path = "C:\\Users\\Admin";
C. string path = 'C:\Users\Admin';
D. string path = `C:\Users\Admin`;
Solution
Step 1: Recall verbatim string syntax
Verbatim strings start with @ and use double quotes, preserving backslashes as-is.
Step 2: Analyze each option
string path = "C:\\Users\\Admin"; uses normal string with escaped backslashes. string path = @"C:\Users\Admin"; uses @ with double quotes correctly. string path = 'C:\Users\Admin'; uses single quotes which is invalid for strings. string path = `C:\Users\Admin`; uses backticks which are invalid.
Final Answer:
string path = @"C:\Users\Admin"; -> Option A
Quick Check:
Verbatim strings start with @ = A [OK]
Hint: Use @ before quotes for verbatim strings [OK]
Common Mistakes:
Forgetting @ for verbatim strings
Using single quotes for strings
Not escaping backslashes in normal strings
3. What is the output of the following C# code?
string s = "Line1\nLine2";
Console.WriteLine(s);
medium
A. Line1\nLine2
B. Line1\n\nLine2
C. Line1
Line2
D. Line1 Line2
Solution
Step 1: Understand escape sequences in strings
The sequence \n represents a newline character in C# strings.
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.
Final Answer:
Line1
Line2 -> Option C
Quick Check:
\n creates new line = D [OK]
Hint: Escape \n prints new line in output [OK]
Common Mistakes:
Printing \n literally instead of new line
Confusing verbatim strings with normal strings
Expecting spaces instead of new lines
4. Identify the error in this C# string declaration:
string s = @"Hello\nWorld";
medium
A. Escape sequences like \n are not processed in verbatim strings
B. No error, this is correct verbatim string
C. Backslash should be doubled as \\ in verbatim strings
D. Missing semicolon at the end
Solution
Step 1: Understand verbatim string behavior
Verbatim strings treat backslashes literally and do not process escape sequences like \n.
Step 2: Analyze the given string
The string @"Hello\nWorld" will contain the characters \ and n literally, not a newline.
Final Answer:
Escape sequences like \n are not processed in verbatim strings -> Option A
Quick Check:
Verbatim strings ignore escape sequences = B [OK]
Hint: Verbatim strings do not process escape sequences [OK]
Common Mistakes:
Expecting \n to create new line in verbatim strings
Doubling backslashes unnecessarily in verbatim strings
Confusing normal and verbatim string rules
5. You want to create a string that contains the exact text:
C:\Users\Admin\Documents
Which of the following C# declarations will produce this exact string value?
hard
A. string path = "C:\Users\Admin\Documents";
B. string path = @"C:\Users\Admin\Documents";
C. string path = "C:\\Users\\Admin\\Documents";
D. string path = 'C:\Users\Admin\Documents';
Solution
Step 1: Understand how to represent backslashes in strings
In normal strings, backslash is an escape character, so to represent one backslash, you must write \\.
Step 2: Check each option for resulting string
string path = @"C:\Users\Admin\Documents"; uses verbatim string which preserves backslashes literally, producing the exact text with single backslashes. string path = 'C:\Users\Admin\Documents'; uses single quotes which is invalid for strings. string path = "C:\Users\Admin\Documents"; has single backslashes which are escape sequences and will produce the correct path string with single backslashes. string path = "C:\\Users\\Admin\\Documents"; doubles each backslash, resulting in double backslashes in the string, which is not the exact text.
Final Answer:
string path = @"C:\Users\Admin\Documents"; -> Option B
Quick Check:
Verbatim string preserves backslashes literally = D [OK]
Hint: Use verbatim string (@) to preserve backslashes literally [OK]
Common Mistakes:
Using single quotes for strings
Doubling backslashes unnecessarily in verbatim strings