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

String creation and literal types in C Sharp (C#) - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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"
How do you represent a newline character in a regular string literal?
A\n
B@n
C\newline
Dnewline
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
Which keyword is an alias for System.String in C#?
Atext
Bstring
CStringLiteral
Dstr
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'});
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.