C# Numeric suffixes

Description

Numeric suffixes explicitly define the type of a literal.

Suffixes can be either lower or uppercase.

C# typeExample
floatfloat f = 1.0F;
doubledouble d = 1D;
decimaldecimal d = 1.0M;
uint or ulonguint i = 1U;
long or ulongulong 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. 





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var