C# Language Verbatim Strings Verbatim strings instruct the compiler to not use character escapes

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

In a normal string, the backslash character is the escape character, which instructs the compiler to look at the next character(s) to determine the actual character in the string. (Full list of character escapes)

In verbatim strings, there are no character escapes (except for "" which is turned into a "). To use a verbatim string, just prepend a @ before the starting quotes.

This verbatim string

var filename = @"c:\temp\newfile.txt"

Output:

c:\temp\newfile.txt

As opposed to using an ordinary (non-verbatim) string:

var filename = "c:\temp\newfile.txt"

that will output:

c:    emp
ewfile.txt

using character escaping. (The \t is replaced with a tab character and the \n is replace with a newline.)

Live Demo on .NET Fiddle



Got any C# Language Question?