C# FAQ: What are the CSharp character escape sequences
Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio
| CSharp-Online.NET:FAQs |
| edit |
[edit]
What are the C# character escape sequences (\)?
An escape sequence allows you to enter any Unicode character, even if it is not readily available on a standard keyboard. Escape characters may appear within identifiers, strings, and certain other places. An escape character has the following form:
The C# compiler recognizes the following character escape sequences:
| Escape sequence | Interpretation |
\'
| single quote, needed for character literals |
\"
| double quote, needed for string literals |
\\
| backslash, needed for string literals |
\0
| Null (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) |
\uhhhh
| Unicode escape sequence for character with hex value hhhh
|
\Uhhhhhhhh
| Unicode escape sequence for character with hex value hhhhhhhh for generating surrogates |
\v
| Vertical quote (character 11) |
\xh [h][h][h]
| Unicode escape sequence for character with hex value nnnn. Variable length version of \uhhhh
|
Here is an escape sequence example:
string hello = "\u0048\u0065\u006C\u006C\u006F"; Console.Write ("\t" + hello + "!\n"); // " Hello!"
[edit]