CSharp - Data Types char type

Introduction

C#'s char type is aliasing the System.Char type.

It represents a Unicode character and occupies 2 bytes.

A char literal is specified inside single quotes:

char c = 'A';

Escape sequences

Escape sequences express characters that cannot be expressed literally.

An escape sequence is a backslash followed by a character with a special meaning.

For example:
char newLine = '\n';
char backSlash = '\\';

The escape sequence characters are shown in the following table.

Char Meaning Value
\' Single quote0x0027
\" Double quote0x0022
\\ Backslash 0x005C
\0 Null0x0000
\a Alert 0x0007
\b Backspace 0x0008
\f Form feed 0x000C
\n New line0x000A
\r Carriage return 0x000D
\t Horizontal tab 0x0009
\v Vertical tab0x000B

\u (or \x) escape sequence specify Unicode character using four-digit hexadecimal code:

char copyrightSymbol = '\u00A9';
char omegaSymbol     = '\u03A9';
char newLine         = '\u000A';

Char Conversions

An implicit conversion from a char to a numeric type works for the numeric types that can accommodate an unsigned short.

For other numeric types, an explicit conversion is required.