Advertisement



< Prev
Next >



C# Data Types





C# is a strongly types language, which means each and every variable has a specific data type and there is no concept of a type less variable in C#. Each data type tells us the size, range and the type of value that can be stored in a variable.

In C#, there are about 13 built-in data types, which are also known as value types or primitive data types. These value types are categorized into 4 parts. Let us take a look at these categories.




Primitive data types are categorized into 4 parts






Maximum and minimum range of values for integer data types


The integer, floating-point and character data types can store a range of values, which is in between a minimum range and a maximum range.

For many of us who like the reasoning behind equations, we will use a formula to calculate a minimum range and a maximum range of values, that can be stored in the integer data types.


  1. Minimum Range - It is the minimum value that can be stored in a data type.
  2. Maximum Range - It is the maximum value that can be stored in a data type.





For example - The integer data type byte is an unsigned data type. The size of a byte data type is 8 bits. And, as per formula above, the minimum range of value that can be stored in a variable declared as the byte data type is 0, while the maximum range of value is 28-1 i.e. 255. Hence, the range of values for the byte data type(which is unsigned) is 0 to 255.




Understanding the integer data types


Let's see a table of information about all the integer data, with each of their size, minimum and maximum range.



Integer Data Type Size Range

byte

1 byte = 8 bits 0 to 255

sbyte

1 byte = 8 bits -128 to 127

short

2 bytes = 16 bits -32768 to 32767

ushort

2 bytes = 16 bits 0 to 65535

int

4 bytes = 32 bits –2,147,483,648 to 2,147,483,647

uint

4 bytes = 32 bits 0 to 4,294,967,295

long

8 bytes = 64 bits –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

ulong

8 bytes = 64 bits 0 to 18,446,744,073,709,551,615





Please Subscribe

Please subscribe to our social media channels for daily updates.


Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page




Advertisement



Notifications



Please check our latest addition

C#, PYTHON and DJANGO


Advertisement