Integral data types in C#

C# supports the concept of unsigned and signed integer types. In this article we discuss about both types of integer datatypes:

Signed Integer type:

Signed integer types can hold both positive and negative numbers, such as 23,-34 etc. . Tables shows size and range of all four signed integer datatype. It should be remembered that wider datatype require more time for manipulation and therefore it is advisable to use smaller data types wherever possible.

TypeSize (Byte)Min ValueMax ValueDeclaration
Sbyte1-128127 Sbyte X = 2;
Short2-3276832767Short X = -24656;
Int4-2,147,483,648 2,147,483,647Int X = 4585213;
Long8-9,223,372,036,854,775,8089,223,372,036,854,775,807Long X = 7854295399514;


Unsigned integer type:

We can increase the size of the positive value store in an integer type by making it unsigned. For example 1 sbyte can store value in the range of -123 to 127, however by making it byte it can handle value in the range of 0 to 255.

TypeSize (Byte)Min ValueMax ValueDeclaration
byte10255 byte X = 2;
Ushort2065,535Ushort X = 65533;
Uint404,294,967,295Uint X = 4294986295;
Ulong8018,446,744,073,709,551,615Ulong X = 11,446744073709551615;