C# Numeric suffixes

In this chapter you will learn:

  1. What C# Numeric suffixes
  2. Example for 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. 

Next chapter...

What you will learn in the next chapter:

  1. C# float vs double types
  2. float point value literal: 3.281f and 5E-02
  3. Use Remainder Operator on float point data type
  4. floats and arithmetic operators
Home »
  C# Tutorial »
    C# Language »
      C# Data Types
C# Predefined Type Taxonomy
C# Numeric Types
C# Numeric Literals
C# Numeric suffixes
C# float and double
C# Float and Double Special Values
C# decimal
C# Numeric Conversions
C# Bool Type
C# char type
C# String Type