C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Note: Literal suffixes on constants actually generate conv instructions. This means they work the same as runtime casts.
Letters: The letters L, D, F, U, M and UL are appended to the end of the integral literals in the declarations.
And: An "L" instructors the C# compiler that 10000 is a long type. The MSIL generated is similar to using casts such as (long)10000.
IL DisassemblerC# program that uses literal number suffixes
using System;
class Program
{
static void Main()
{
// Use long suffix.
long l1 = 10000L;
// Use double suffix.
double d1 = 123.764D;
// Use float suffix.
float f1 = 100.50F;
// Use unsigned suffix.
uint u1 = 1000U;
// Use decimal suffix.
decimal m2 = 4000.1234M;
// Use unsigned suffix and long suffix.
ulong u2 = 10002000300040005000UL;
}
}
Syntax table
Suffix type: unsigned int
Character: U
Example: uint x = 100U;
Suffix type: long
Character: L
Example: long x = 100L;
Suffix type: unsigned long
Character: UL
Example: ulong x = 100UL;
Suffix type: float
Character: F
Example: float x = 100F;
Suffix type: double
Character: D
Example: double x = 100D;
Suffix type: decimal
Character: M
Example: decimal x = 100M;
Warning: The "l" suffix is easily confused with the digit 1—use L for clarity. The screenshot shows this warning in the IDE.
Examples of lowercase suffixes
Lowercase suffix: long x = 10000l; // Is that 100001 or 10000l?
Uppercase suffix: long x = 10000L; // It's 10000L.
Note: The specification defines how numbers are converted when used as operands, but these suffixes can force certain conversions.