Difference between uint, UInt16, UInt32 and UInt64 in C#

C# contrasts between uint, UInt16, UInt32 and UInt64: Here, we will realize what are the contrasts between uint, UInt16, UInt32 and UInt64 in C#?

uint, UInt16, UInt32 and UInt64 are utilized to speak to unsigned numbers with values running dependent on their abilities/involved size in the memory.

These sorts work with positive qualities as it were. Every one of these sorts is the equivalent in nature yet unique dependent on the worth extents.

The distinction between uint, UInt16, UInt32 and UInt64

1) UInt16

  1. UInt16 speaks to 16-bits (2-bytes) unsigned the whole number.
  2. UInt16 possesses 16-bits (2-bytes) space in the memory.
  3. According to the 2-bytes information limit, a UInt16’s worth limit is 0 to +65535.

Example:

Think about the code – Here, we are printing required size, type, least and most extreme worth, variable affirmation, and the task of a UInt16.

using System;
using System.Text;

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

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

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

Output:

UInt16 occupies 2 bytes
UInt16 type is: System.UInt16
UInt16 MIN value: 0
UInt16 MAX value: 65535

a = 12345, b = 65000

2) UInt32/uint

  1. uint is a nom de plume of UInt32, in this way, uint and UInt32 are a similar kind.
  2. UInt32 speaks to 32-bits (4-bytes) unsigned the whole number.
  3. UInt32 involves 32-bits (4-bytes) space in the memory.
  4. According to the 4-bytes information limit, a UInt32’s worth limit is 0 to +4294967295.

Example:

Think about the code – Here, we are printing required size, type, least and most extreme worth, variable revelation, and the task of a UInt32 or uint.

using System;
using System.Text;

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

            //UInt32 variables
            UInt32 a = 289812345;
            UInt32 b = 90909;
            Console.WriteLine("a = {0}, b = {1}", a, b);
            Console.WriteLine();

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

            //uint variables
            uint x = 289812345;
            uint y = 90909;
            Console.WriteLine("x = {0}, y = {1}", x, y);

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

Output:

UInt32 occupies 4 bytes
UInt32 type is: System.UInt32
UInt32 MIN value: 0
UInt32 MAX value: 4294967295

a = 289812345, b = 90909

uint occupies 4 bytes
uint type is: System.UInt32
uint MIN value: 0
uint MAX value: 4294967295

x = 289812345, y = 90909

3) UInt64

UInt64 speaks to 64-bits (8-bytes) unsigned number.

UInt64 possesses 64-bits (8-bytes) space in the memory.

According to the 8-bytes information limit, a UInt64’s worth limit is 0to +18446744073709551615.

Example:

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

using System;
using System.Text;

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

            //UInt64 variables
            UInt64 a = 289818278722345;
            UInt64 b = 98983989;
            Console.WriteLine("a = {0}, b = {1}", a, b);
            Console.WriteLine();

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

Output:

UInt64 occupies 8 bytes
UInt64 type is: System.UInt64
UInt64 MIN value: 0
UInt64 MAX value: 18446744073709551615

a = 289818278722345, b = 98983989

Leave a Comment

error: Alert: Content is protected!!