short keyword in C#

Keywords are the words in a language that are used for some internal process or represent some predefined actions. short is a keyword that is used to declare a variable which can store a signed integer value from the range -32, 768 to 32, 767. It is an alias of System.Int16.

Syntax:

short variable_name = value;

short keyword occupies 2 bytes (16 bits) space in the memory.

Example:

Input: num: 2

Output: num: 2
        Size of a short variable: 2

Input: num = 20200

Output: num: 20200
        Type of num: System.Int16
        Size of a short variable: 2

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program for short keyword
using System;
using System.Text;
  
class Prog {
  
    static void Main(string[] args)
    {
        // variable declaration
        short num = 2;
  
        // to print value
        Console.WriteLine("num: " + num);
  
        // to print size
        Console.WriteLine("Size of a short variable: " + sizeof(short));
    }
}

chevron_right


Output:

num: 2
Size of a short variable: 2

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program for short keyword
using System;
using System.Text;
  
namespace Test {
  
class Prog {
  
    static void Main(string[] args)
    {
        // variable declaration
        short num = 20200;
  
        // to print value
        Console.WriteLine("num: " + num);
  
        // to print type of variable
        Console.WriteLine("Type of num: " + num.GetType());
  
        // to print size
        Console.WriteLine("Size of a short variable: " + sizeof(short));
  
        // to print 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();
    }
}
}

chevron_right


Output:

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



My Personal Notes arrow_drop_up

Recommended Posts:

    Article Tags :

    Be the First to upvote.


    Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.