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

Verbatim and raw string literals in C Sharp (C#) - Mini Project: Build & Apply

Choose your learning style9 modes available
Verbatim and Raw String Literals in C#
📖 Scenario: You are creating a simple program to store and display file paths and multi-line text messages exactly as they are written, including special characters and line breaks.
🎯 Goal: Build a C# program that uses verbatim and raw string literals to store and print a file path and a multi-line message with quotes and line breaks preserved.
📋 What You'll Learn
Create a string variable called filePath using a verbatim string literal with the exact value C:\Users\Public\Documents\Report.txt.
Create a string variable called message using a raw string literal that contains the exact multi-line text:
"Dear User,\nPlease review the attached report.\nThanks,\nAdmin" including the quotes and line breaks.
Print the filePath variable.
Print the message variable.
💡 Why This Matters
🌍 Real World
Handling file paths and multi-line text messages exactly as typed is common in configuration files, logs, and user messages.
💼 Career
Knowing how to use verbatim and raw string literals helps developers write clearer and less error-prone code when dealing with strings that contain special characters or multiple lines.
Progress0 / 4 steps
1
Create the file path string with a verbatim literal
Create a string variable called filePath using a verbatim string literal with the exact value C:\\Users\\Public\\Documents\\Report.txt.
C Sharp (C#)
Need a hint?

Use the @"..." syntax to create a verbatim string literal in C#.

2
Create the multi-line message string with a raw string literal
Create a string variable called message using a raw string literal that contains the exact multi-line text including quotes and line breaks:
"Dear User,\nPlease review the attached report.\nThanks,\nAdmin".
C Sharp (C#)
Need a hint?

Use triple double quotes """...""" to create a raw string literal in C# 11+.

3
Print the file path string
Write a Console.WriteLine statement to print the filePath variable.
C Sharp (C#)
Need a hint?

Use Console.WriteLine(filePath); to print the file path.

4
Print the multi-line message string
Write a Console.WriteLine statement to print the message variable.
C Sharp (C#)
Need a hint?

Use Console.WriteLine(message); to print the multi-line message.