C# Numeric suffixes
Description
Numeric suffixes explicitly define the type of a literal.
Suffixes can be either lower or uppercase.
C# type | Example |
---|---|
float | float f = 1.0F; |
double | double d = 1D; |
decimal | decimal d = 1.0M; |
uint or ulong | uint i = 1U; |
long or ulong | ulong i = 1UL; |
Example
The F
and M
suffixes should always be applied
when specifying float or decimal literals.
Without the F
suffix, the following line would not
compile, because 4.5 would be inferred to be of type double, which has no implicit
conversion to float.
The same principle is true for a decimal literal:
float f = 4.5F;
decimal d = -1.23M; // Will not compile without the M suffix.