Literal suffix

You can use suffix to define literals explicitly.

The following table lists the suffix used by C#.

LetterC# typeExample
Ffloatf = 1.0F;
Ddoubled = 1D;
Mdecimaldecimal d = 1.0M;
Uuint or ulonguint i = 1U;
Llong or ulongulong 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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.