Character combinations consisting of a backslash (\) followed by a letter or by a combination of digits are called "escape sequences." To represent a newline character, single quotation mark, or certain other characters in a character constant, you must use escape sequences. An escape sequence is regarded as a single character and is therefore valid as a character constant.
Escape sequences are typically used to specify actions such as carriage returns and tab movements on terminals and printers. They are also used to provide literal representations of nonprinting characters and characters that usually have special meanings, such as the double quotation mark ("). The following table lists the ANSI escape sequences and what they represent.
C# defines the following character escape sequences:
\'
- single quote, needed for character literals\"
- double quote, needed for string literals\\
- backslash\0
- Unicode character 0\a
- Alert (character 7)\b
- Backspace (character 8)\f
- Form feed (character 12)\n
- New line (character 10)\r
- Carriage return (character 13)\t
- Horizontal tab (character 9)\v
- Vertical quote (character 11)\uxxxx
- Unicode escape sequence for character with hex value xxxx\xn[n][n][n]
- Unicode escape sequence for character with hex value nnnn (variable length version of \uxxxx)\Uxxxxxxxx
- Unicode escape sequence for character with hex value xxxxxxxx (for generating surrogatessource : MSDN
Comments