Can char type hold escape sequences?  
Author Message
Karim Hemani





PostPosted: Visual C# Language, Can char type hold escape sequences? Top

Hi,

In Learning C#, the authors states that the char type can represent a simple character (A), a Unicode character (\u0041), or an escape character enclosed by single quote marks ('\n'). Isn't '\n' an escape sequence rather than an escape character. Isn't "\" alone the escape character Can the char type hold entire escape sequences then, which are a group of characters beginning with an escape character, and which can be used as a command to control devices like the display Please clarify.

Karim



Visual C#1  
 
 
ShellShock





PostPosted: Visual C# Language, Can char type hold escape sequences? Top

The compiler converts the two textual characters \n in your source code into a single character (code 10) in the compiled program. So textually, '\n' is an escape sequence of characters, and \ is the escape character; in compiled code the escape sequence of characters '\n' is converted into a single escaped character (line feed). The same applies for other escaped characters. This is how the char type can represent single characters 'a' and escaped characters '\n', which are really single characters in the program, but are written using two textual characters (because there is no single letter that can represent them textually).