C Sharp ( C# ) Literals


C Sharp Literals is assigning a value to a variable.

In C#, literals refer to fixed values that are assigned to different variables  C# literals can be of any simple or primitive type. The way a variable is defined using a certain datatype tells us how the literal should be given.

Here are examples how literals are assigned.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            //Assigning a char
            char a = 'Z';
            //Assigning a string
            string s = "Hello... how are you ?";
            //Assigning an integer
            int i = 10;
            //Assigning a uint
            uint j = 10u;
            uint k = 10U;
            //Assigning a float
            float f = 10.5678F;
            float g = 10.567f;
            //Assinging a long
            long l = 100l;
            long m = 100L;
            //Assigning a decimal
            decimal d = 5.6m;
            decimal e = 6.7M;
            //Assigning a double
            double z = 1.24d;
            double y = 3.456979879D;
            //Assigning a byte;
            byte b = 10;
            //Assiging a bool;
            bool value = true;
            bool value1 = false;
            //Assigning unsigned values for long
            ulong ul = 487UL;
            //Assigning signed byte
            sbyte sb = 20;
            //Assigning HexaDecimal Values
            int hexa = 0x2a; //This represents a decimal value of 2a which is 32+10 = 42           
        }
    }
}

No comments: