ushort keyword in C#

C# ushort keyword: Here, we will find out about the ushort keyword in C#, what is ushort keyword, how to utilize it in C#?

C# ushort keyword:

In C#, ushort is a keyword which is utilized to proclaim a variable that can store an unsigned whole number an incentive between the scope of 0 to 65,535. ushort keyword is a false name of System.UInt16.

It involves 2 bytes (16 bits) space in the memory.

Syntax:

    ushort variable_name = value;

C# code to show an example of ushort keyword:

using System;
using System.Text;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            //variable declaration
            ushort num = 12345;

            //printing value
            Console.WriteLine("num: " + num);
            //printing type of variable
            Console.WriteLine("Type of num: " + num.GetType());
            //printing size
            Console.WriteLine("Size of a ushort variable: " + sizeof(ushort));
            //printing minimum & maximum value of ushort
            Console.WriteLine("Min value of ushort: " + ushort.MinValue);
            Console.WriteLine("Max value of ushort: " + ushort.MaxValue);

            //hit ENTER to exit
            Console.ReadLine();
        }
    }
}

Here, we are announcing a ushort variable num, instating it with the worth 12345 and printing its worth, type and size of a ushort type variable.

Output:

num: 12345
Type of num: System.UInt16
Size of a ushort variable: 2
Min value of ushort: 0
Max value of ushort: 65535

Leave a Comment

error: Alert: Content is protected!!