A literal is a source code representation of a value.
There are two Boolean literal values: true and false.
The type of a boolean-literal is bool.
Integer literals are used to write values of types int, uint, long, and ulong. Integer literals have two possible forms: decimal and hexadecimal.
Integer Literals can be specified as the number without any fractions.
An integer literal can be hexadecimal, octal or decimal.
To specify hexadecimal and octal integer literals we used prefix as 0x/0X and o/O respectively. No prefix is used for the decimal.
The type of an integer literal is determined as follows:
These are some examples of Integer Literals:
95 // decimal 0xAB10 // hexadecimal 076 // octal 12u // unsigned int 32ul // unsigned long 45L // long 39 // int
Real literals are used to write values of types float, double, and decimal.
If no real type suffix is specified, the type of the real literal is double. Otherwise, the real type suffix determines the type of the real literal, as follows:
Here are some examples of the Floating Point Literals:
3.14f // float value 3.123456 // double value 314.e54 // exponent floating value 234.55m //decimal value
A character literal represents a single character, and usually consists of a character in quotes, as in 'a'.
A character that follows a backslash character (\) in a character must be one of the following characters: ', ", \, 0, a, b, f, n, r, t, u, U, x, v. Otherwise, a compile-time error occurs.
A hexadecimal escape sequence represents a single Unicode character, with the value formed by the hexadecimal number following "\x".
If the value represented by a character literal is greater than U+FFFF, a compile-time error occurs.
A simple escape sequence represents a Unicode character encoding, as described in the table below.
|\n||New line (linefeed)|
C# supports two forms of string literals: regular string literals and verbatim string literals.
A regular string literal consists of zero or more characters enclosed in double quotes, as in "hello", and may include both simple escape sequences (such as \t for the tab character) and hexadecimal and Unicode escape sequences.
A verbatim string literal consists of an @ character followed by a double-quote character, zero or more characters, and a closing double-quote character. A simple example is @"hello". In a verbatim string literal, the characters between the delimiters are interpreted verbatim, the only exception being a quote-escape-sequence. In particular, simple escape sequences and hexadecimal and Unicode escape sequences are not processed in verbatim string literals. A verbatim string literal may span multiple lines.
The type of a null-literal is the null type.