char escape sequence

Some characters are not typeable from keyboard directly. For example, the new line character.

In such circumstance we use escape sequence to represent the special character value.

An escape sequence starts with backslash.

CharMeaningValue
\'Single quote0x0027
\"Double quote0x0022
\\Backslash0x005C
\0Null0x0000
\aAlert0x0007
\bBackspace0x0008
\fForm feed0x000C
\nNew line0x000A
\rCarriage return0x000D
\tHorizontal tab0x0009
\vVertical tab0x000B

The following example shows how to use the escape sequence.


using System;

class Program
{
    static void Main(string[] args)
    {
        char newLine = '\n';
        char singleQuote = '\'';

        Console.WriteLine(newLine);
        Console.WriteLine(singleQuote);

    }
}

The output:


'

The following code shoes how to create unicode char literal:


using System;

class Program
{
    static void Main(string[] args)
    {
        char copyrightSymbol = '\u00A9';
        char aSymbol = '\u03A9';

        Console.WriteLine(copyrightSymbol);
        Console.WriteLine(aSymbol);

    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.