Difference between Int16 and UInt16 in C#

C# Int16 and UInt16 Differences: Here, we will find out about the contrasts between C# Int16 and C# UInt16 information types.

C# Int16 and C# UInt16

In C#, Int16 known as a marked whole number of 2 bytes which can store the two kinds of qualities including negative and positive between the scopes of – 32768 to +32767.

UInt16 known as an unsigned whole number of 2 bytes which can store just positive qualities between the scopes of 0 to 65535.

Contrasts somewhere in the range of ‘Int16’ and ‘UInt16’

Int16UInt16
Int16 stands for signed integer.UInt16 stands for an unsigned integer.
It’s the capacity to store the value is -32768 to +32767.Its the capacity to store the value is 0 to 65535.
It can store negative and positive integers.It can store only positive integers.
It occupies 2-bytes space in the memory.It also occupies 2-bytes space in the memory.
Declaration syntax:
Int16 variable;
Declaration syntax:
UInt16 variable;

Example:

In this example, to clarify the contrasts somewhere in the range of Int16 and UInt16 in C#, we are printing their base and most extreme qualities, we are additionally announcing two clusters – arr1 is a marked number sort and arr2 is an unsigned whole number sort. Instating the exhibits by comparing negative and positive qualities dependent on their ability.

using System;
using System.Text;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            //Int16 value range 
            Console.WriteLine("Int16 value capacity...");
            Console.WriteLine("Min: {0}, Max: {1}\n", Int16.MinValue, Int16.MaxValue);

            //UInt16 value range 
            Console.WriteLine("UInt16 value capacity...");
            Console.WriteLine("Min: {0}, Max: {1}\n", UInt16.MinValue, UInt16.MaxValue);

            //Int16 array
            Int16[] arr1 = { -32768, 0, 1000, 32000, 32767};
            Console.WriteLine("UInt16 array elements...");
            foreach (Int16 num in arr1)
            {
                Console.WriteLine(num);
            }
            Console.WriteLine();

            //UInt16 array
            UInt16[] arr2 = { 0, 100, 23000, 65000, 65525};
            Console.WriteLine("UInt16 array elements...");
            foreach (UInt16 num in arr2)
            {
                Console.WriteLine(num);
            }

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

Output:

Int16 value capacity...
Min: -32768, Max: 32767

UInt16 value capacity...
Min: 0, Max: 65535

UInt16 array elements...
-32768
0
1000
32000
32767

UInt16 array elements...
0
100
23000
65000
65525

Leave a Comment

error: Alert: Content is protected!!