C# FAQ: What is a verbatim string literal

Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio


Jump to: navigation, search
CSharp-Online.NET:FAQs
edit

What is a verbatim string literal (@)?

A verbatim string literal is a string literal preceded by the "at sign" (@). For example:

@"c:\Program Files"

The @ character indicates that no character interpretations should be applied between the subsequent quotation marks ("). So, as in the preceding example, verbatim string literals can contain unescaped backslashes—the backslash (\) is an escape character in regular string literals—and line separators such as carriage return (CR) and linefeed (LF). A normal string literal would look like this:

"c:\\Program Files"

To insert a double quote (") within a verbatim literal, simply double it like this:

@"Her child is ""difficult""."

Typical uses for verbatim string literals include:

  • file path specifications
  • SQL strings
  • white space inculsions (e.g. line separators)
  • XML strings

See also



Personal tools