C# Numeric suffixes
In this chapter you will learn:
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.
Next chapter...
What you will learn in the next chapter:
- C# float vs double types
- float point value literal: 3.281f and 5E-02
- Use Remainder Operator on float point data type
- floats and arithmetic operators