CSharp - Data Types Numeric suffixes

Introduction

Numeric suffixes explicitly define the type of a literal.

You can set a literal type by using suffix.

By default 1.0 is inferred as double by C# compiler, if you want to make it float type, you can add F as suffix.

Suffixes can be either lower or uppercase

Category C# type Example
F float float f = 1.0F;
D double double d = 1D;
M decimaldecimal d = 1.0M;
U uint uint i = 1U;
L long long i = 1L;
ULulong ulong i = 1UL;

F and M suffixes are the most useful and should always be applied when specifying float or decimal literals.

Demo

using System;
class MainClass/* ww  w.j ava 2  s .  c  o  m*/
{
   public static void Main(string[] args)
   {

     Console.WriteLine (        1.0.GetType());  // Double  (double)
     Console.WriteLine (       1E06.GetType());  // Double  (double)
     Console.WriteLine (          1.GetType());  // Int32   (int)
     Console.WriteLine ( 0xF0000000.GetType());  // UInt32  (uint)
     Console.WriteLine (0x100000000.GetType());  // Int64   (long)
     
     
     Console.WriteLine (        1.0F.GetType());  
     Console.WriteLine (       1E06F.GetType());  
     Console.WriteLine (          1U.GetType());  
   }
}

Result

Quiz