Integral data types in C#

HTML clipboard

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.

Type

Size (Byte)

Min Value

Max Value

Declaration

Sbyte

1

-128

127

 Sbyte X = 2;

Short

2

-32768

32767

Short X = -24656;

Int

4

-2,147,483,648

 2,147,483,647

 

Int X = 4585213;

Long

8

-9,223,372,036,854,775,808

9,223,372,036,854,775,807

Long X = 7854295399514;

 

Note: If the value represented by an integer literal exceeds the range of ulong, a compilation error will occur.

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.

Type

Size (Byte)

Min Value

Max Value

Declaration

byte

1

0

255

 byte X = 2;

Ushort

2

0

65,535

Ushort X = 65533;

Uint

4

0

4,294,967,295

Uint X =4294986295;

Ulong

8

0

18,446,744,073,709,551,615

Ulong X = 11,446744073709551615;


Similar Articles