Share via


C# Escape Characters

Like other C-based languages, C# makes use of Escape Sequences or Escape Characters when working with string literals. Escape characters are designed to ensure that special text in a string literal appears as it should. The most common usages are for single and double quotes, tabbed spaces, and new line characters. Every escape character begins with a backslash (\ and is followed by a value or token.

The most common escape characters are represented in the table below:

Escape Character Representation
\’ Single quotation mark
\” Double quotation mark
\\ Backslash (useful for file and network paths definitions)
\? Literal question mark
\a System alert (beep)
\b Backspace
\f Formfeed (next page)
\n New line
\r Carriage return (beginning of a line)
\t Horizontal tab
\v Vertical tab

Note: If a character that does not appear in the table above is preceded with a backslash, the character value is returned. For example, if the compiler sees \x it will be treated as x.