ECMA-334 C# Language Specification9.4.4.2: Integer literals |
Integer literals are used to write values of types int , uint , long , and ulong . Integer literals have two possible forms: decimal and hexadecimal.
decimal-integer-literal hexadecimal-integer-literal decimal-digits integer-type-suffixopt decimal-digit decimal-digits decimal-digit 0 1 2 3 4 5 6 7 8 9 U u L l UL Ul uL ul LU Lu lU lu 0x hex-digits integer-type-suffixopt 0X hex-digits integer-type-suffixopt hex-digit hex-digits hex-digit 0 1 2 3 4 5 6 7 8 9 A B C D E F a b c d e fThe type of an integer literal is determined as follows:
If the value represented by an integer literal is outside the range of the ulong type, a compile-time error occurs.
To permit the smallest possible int and long values to be written as decimal integer literals, the following two rules exist:
decimal-integer-literal with the value 2147483648 (2 integer-type-suffix appears as the token immediately following a unary minus operator token (14.6.2), the result is a constant of type int with the value decimal-integer-literal is of type uint . decimal-integer-literal with the value 9223372036854775808 (2 integer-type-suffix or the integer-type-suffix L or l appears as the token immediately following a unary minus operator token (14.6.2), the result is a constant of type long with the value decimal-integer-literal is of type ulong .