In C#, int16
and uint16
are two data types that are used for byte integers of 2. The difference is that int16
is used for signed integers. This means that it can store both negative and positive types of values. The range of values it takes is from -32768 to 32767.
The uint16
, which works on unsigned integers of 2 bytes, stores only positive values between the range 0 to 65535.
Int16 variableUInt16 variable
variable
: this is the variable that we want to create either as an Int16
or as a UInt16
integer.
using System;class HelloWorld{static void Main(){// create byte variables from 0-255Int16 b1 = -25;Int16 b2 = 100;Int16 b3 = -255;// create sbyte variables from -128 - 127UInt16 sb1 = 1200;UInt16 sb2 = 234;UInt16 sb3 = 100;// print values and data typesConsole.WriteLine("{0} is {1}, with range of {2} to {3}", b1, b1.GetTypeCode(), Int16.MinValue, Int16.MaxValue);Console.WriteLine("{0} is {1}, with range of {2} to {3}", b2, b2.GetTypeCode(), Int16.MinValue, Int16.MaxValue);Console.WriteLine("{0} is {1}, with range of {2} to {3}", b3, b3.GetTypeCode(), Int16.MinValue, Int16.MaxValue);Console.WriteLine("{0} is {1}, with range of {2} to {3}", sb1, sb1.GetTypeCode(), UInt16.MinValue, UInt16.MaxValue);Console.WriteLine("{0} is {1}, with range of {2} to {3}", sb2, sb2.GetTypeCode(), UInt16.MinValue, UInt16.MaxValue);Console.WriteLine("{0} is {1}, with range of {2} to {3}", sb3, sb3.GetTypeCode(), UInt16.MinValue, UInt16.MaxValue);}}
Int16
variables and initialize them.UInt16
variables and initialize them.