Mega Code Archive

 
Categories / C# Book / 01 Language Basics
 

0024 Literal suffix

You can use suffix to define literals explicitly. The following table lists the suffix used by C#. Letter C# type Example F float f = 1.0F; D double d = 1D; M decimal decimal d = 1.0M; U uint or ulong uint i = 1U; L long or ulong ulong i = 1UL; using System; class Program { static void Main(string[] args) { Console.WriteLine(1D.GetType()); Console.WriteLine(1.6F.GetType()); Console.WriteLine(1.1M.GetType()); Console.WriteLine(1U.GetType()); Console.WriteLine(1UL.GetType()); } } The output: System.Double System.Single System.Decimal System.UInt32 System.UInt64 We can use the suffix when initializing the variables as well. using System; class Program { static void Main(string[] args) { decimal d = 1.1M; Console.WriteLine(d); } } The output: 1.1