C# Escape Characters

This article is also available on the Microsoft TechNet Wiki.

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.


About Ken Cenerelli
I am a technical writer/programmer writer/content developer, .NET developer, Microsoft MVP, public speaker, blogger, and Microsoft Azure nerd. I blog about technology at kencenerelli.wordpress.com and am on Twitter via @KenCenerelli.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: