Difference between int, Int16, Int32 and Int64 in C#

Difference between int, Int16, Int32 and Int64 in C#

C# contrasts between int, Int16, Int32 and Int64: Here, we will realize what are the contrasts between int, Int16, Int32 and Int64 in C#?

int, Int16, Int32 and Int64 are utilized to speak to marked whole numbers with values going dependent on their abilities/involved size in the memory. These sorts can work with negative and positive qualities. Every one of these sorts is the equivalent in nature however extraordinary dependent on the worth reaches.

The contrast between int, Int16, Int32 and Int64

1) Int16

  1. Int16 speaks to 16-bits (2-bytes) marked the whole number.
  2. Int16 involves 16-bits (2-bytes) space in the memory.
  3. According to the 2-bytes information limit, an Int16‘s worth limit is – 32768 to +32767.

Example:

Think about the code – Here, we are printing required size, type, least and greatest worth, variable presentation, and the task of an Int16.

using System;
using System.Text;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            //printing Int16 capacity, type, MIN & MAX value
            Console.WriteLine("Int16 occupies {0} bytes", sizeof(Int16));
            Console.WriteLine("Int16 type is: {0}", typeof(Int16));
            Console.WriteLine("Int16 MIN value: {0}", Int16.MinValue);
            Console.WriteLine("Int16 MAX value: {0}", Int16.MaxValue);
            Console.WriteLine();

            //Int16 variables
            Int16 a = 12345;
            Int16 b = -12345;
            Console.WriteLine("a = {0}, b = {1}", a, b);

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

Output:

Int16 occupies 2 bytes
Int16 type is: System.Int16
Int16 MIN value: -32768
Int16 MAX value: 32767

a = 12345, b = -12345

2) Int32/int

  1. int is a nom de plume of Int32, along these lines, int and Int32 are a similar kind.
  2. Int32 speaks to 32-bits (4-bytes) marked the whole number.
  3. Int32 possesses 32-bits (4-bytes) space in the memory.
  4. According to the 4-bytes information limit, an Int32’s worth limit is – 2147483648 to +2147483647.

Example:

Think about the code – Here, we are printing required size, type, least and most extreme worth, variable presentation, and the task of an Int32 or int.

using System;
using System.Text;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            //printing Int32 capacity, type, MIN & MAX value
            Console.WriteLine("Int32 occupies {0} bytes", sizeof(Int32));
            Console.WriteLine("Int32 type is: {0}", typeof(Int32));
            Console.WriteLine("Int32 MIN value: {0}", Int32.MinValue);
            Console.WriteLine("Int32 MAX value: {0}", Int32.MaxValue);
            Console.WriteLine();

            //Int32 variables
            Int32 a = 289812345;
            Int32 b = -290012345;
            Console.WriteLine("a = {0}, b = {1}", a, b);
            Console.WriteLine();

            //printing int capacity, type, MIN & MAX value
            Console.WriteLine("int occupies {0} bytes", sizeof(int));
            Console.WriteLine("int type is: {0}", typeof(int));
            Console.WriteLine("int MIN value: {0}", int.MinValue);
            Console.WriteLine("int MAX value: {0}", int.MaxValue);
            Console.WriteLine();

            //int variables
            int x = 289812345;
            int y = -290012345;
            Console.WriteLine("x = {0}, y = {1}", x, y);

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

Output:

Int32 occupies 4 bytes
Int32 type is: System.Int32
Int32 MIN value: -2147483648
Int32 MAX value: 2147483647

a = 289812345, b = -290012345

int occupies 4 bytes
int type is: System.Int32
int MIN value: -2147483648
int MAX value: 2147483647

x = 289812345, y = -290012345

3) Int64

  1. Int64 speaks to 64-bits (8-bytes) marked number.
  2. Int64 possesses 64-bits (8-bytes) space in the memory.
  3. According to the 8-bytes information limit, an Int64’s worth limit is – 9223372036854775808 to +9223372036854775807.

Example:

Think about the code – Here, we are printing required size, type, least and greatest worth, variable presentation, and the task of an Int64.

using System;
using System.Text;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            //printing Int64 capacity, type, MIN & MAX value
            Console.WriteLine("Int64 occupies {0} bytes", sizeof(Int64));
            Console.WriteLine("Int64 type is: {0}", typeof(Int64));
            Console.WriteLine("Int64 MIN value: {0}", Int64.MinValue);
            Console.WriteLine("Int64 MAX value: {0}", Int64.MaxValue);
            Console.WriteLine();

            //Int64 variables
            Int64 a = 289818278722345;
            Int64 b = -290287827012345;
            Console.WriteLine("a = {0}, b = {1}", a, b);
            Console.WriteLine();

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

Output:

Int64 occupies 8 bytes
Int64 type is: System.Int64
Int64 MIN value: -9223372036854775808
Int64 MAX value: 9223372036854775807

a = 289818278722345, b = -290287827012345

Recent Posts

error: Alert: Content is protected!!