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

String creation and literal types in C Sharp (C#) - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
String Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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);
AC:\\Users\\Admin\\Documents
BC:\Users\Admin\Documents
CC:/Users/Admin/Documents
DC:UsersAdminDocuments
Attempts:
2 left
💡 Hint
Look at how the @ symbol affects backslashes in string literals.
Predict Output
intermediate
2: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);
ASum of 5 and 10 is 15
BSum of x and y is x + y
CSum of {x} and {y} is {x + y}
DSum of 5 and 10 is x + y
Attempts:
2 left
💡 Hint
Remember how variables inside $"..." strings are evaluated.
🔧 Debug
advanced
2: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);
AOutput: Hello (newline) World
BRuntimeException: Newline not allowed in string
CSyntaxError: Invalid escape sequence
DCompile-time error: Unterminated string literal
Attempts:
2 left
💡 Hint
Check how escape sequences like \n work in C# strings.
🧠 Conceptual
advanced
2:00remaining
How many characters does this string contain?
What is the length of the string created by this code? string s = @"Line1\nLine2";
A11
B9
C10
D12
Attempts:
2 left
💡 Hint
Remember that verbatim strings treat backslashes as normal characters.
Predict Output
expert
3: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);
APath: C:\Users\\Documents
BPath: C:\Users\{Environment.UserName}\Documents
CPath: C:\Users\Admin\Documents
DPath: C:Users{Environment.UserName}Documents
Attempts:
2 left
💡 Hint
The string uses both $ and @ symbols. Consider how interpolation and verbatim strings combine.