short keyword in C#

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

C# short keyword:

In C#, short is a keyword which is utilized to proclaim a variable that can store a marked number an incentive between the scope of – 32,768 to 32,767. the short keyword is a pseudonym of System.Int16.

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

Syntax:

    short variable_name = value;

C# code to exhibit an example of short keyword:

Here, we are pronouncing a short factor num, introducing it with the worth 12345 and printing its worth, type and size of a short kind variable.

using System;
using System.Text;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            //variable declaration
            short 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 short variable: " + sizeof(short));
            //printing minimum & maximum value of short
            Console.WriteLine("Min value of short: " + short.MinValue);
            Console.WriteLine("Max value of short: " + short.MaxValue);

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

Output:

num: 12345
Type of num: System.Int16
Size of a short variable: 2
Min value of short: -32768
Max value of short: 32767

Leave a Comment

error: Alert: Content is protected!!