char escape sequence

In this chapter you will learn:

  1. What value need escape

Escape char

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;//from ja va2  s. c  om

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;/*  j av  a 2s.com*/

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

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

    }
}

Next chapter...

What you will learn in the next chapter:

  1. How to change case for C# char value
  2. Convert character to upper case
Home » C# Tutorial » bool, char
bool
bool and if statement
bool value to string
Parse string to bool value
char type
char escape sequence
char case
Compare char value
char min/max value
Is char a digit
Is char a letter
Is char a symbol
Is char a Separator
Is char white space
Convert to char
UTF-16 Character