Challenge - 5 Problems
String Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this string literal code?
Consider the following C# code snippet. What will be printed to the console?
C Sharp (C#)
string path = @"C:\Users\Admin\Documents";
Console.WriteLine(path);Attempts:
2 left
💡 Hint
Look at how the @ symbol affects backslashes in string literals.
✗ Incorrect
The @ symbol before the string makes it a verbatim string literal, so backslashes are treated as normal characters and do not need to be escaped. Thus, the output shows single backslashes.
❓ Predict Output
intermediate2:00remaining
What does this string interpolation print?
Given the code below, what is the output?
C Sharp (C#)
int x = 5; int y = 10; string result = $"Sum of {x} and {y} is {x + y}"; Console.WriteLine(result);
Attempts:
2 left
💡 Hint
Remember how variables inside $"..." strings are evaluated.
✗ Incorrect
The $ symbol before the string allows expressions inside braces to be evaluated and inserted into the string. So {x} becomes 5, {y} becomes 10, and {x + y} becomes 15.
🔧 Debug
advanced2:00remaining
What error does this code raise?
Examine the following code. What error will occur when compiling or running it?
C Sharp (C#)
string s = "Hello\nWorld";
Console.WriteLine(s);Attempts:
2 left
💡 Hint
Check how escape sequences like \n work in C# strings.
✗ Incorrect
The \n is a valid escape sequence representing a newline character. The string prints Hello, then a newline, then World.
🧠 Conceptual
advanced2:00remaining
How many characters does this string contain?
What is the length of the string created by this code?
string s = @"Line1\nLine2";
Attempts:
2 left
💡 Hint
Remember that verbatim strings treat backslashes as normal characters.
✗ Incorrect
The string is verbatim, so \n is two characters: a backslash and an 'n'. Counting all characters: L i n e 1 \ n L i n e 2 = 12 characters.
❓ Predict Output
expert3:00remaining
What is the output of this complex string creation?
Analyze the code and determine what is printed:
C Sharp (C#)
string s = $@"Path: C:\Users\{Environment.UserName}\Documents";
Console.WriteLine(s);Attempts:
2 left
💡 Hint
The string uses both $ and @ symbols. Consider how interpolation and verbatim strings combine.
✗ Incorrect
The $@ combination means the string is verbatim and interpolated. Backslashes are literal, and expressions inside braces are evaluated. Environment.UserName is replaced by the current user name, e.g., Admin.