In practical life nobody can carry each and every file, folders or documents with himself except of those which he uses them very frequently or is very important but for those who are not important he need any place like drawer or cabinets to store them and can reuse them whenever he needs. In the same way .Net framework also need any place to store things and can reuse them, these places are called Variables. Variable store values of some specific type and these types are called Data Type. There are various types of data type like integer, float or string.
In order to store any numeric value .Net gives us various types like byte, sbyte, short, ushort, int, uint, long, ulong, float, double from which only float and double can carry decimal values and rest of them can only carry whole number. There are different ranges of maximum and minimum values for different types that they can hold. These ranges depends on the spaces (in bytes) occupied by variables of specific type in the memory.
Byte and sbyte occupies one byte in the memory and it ranges from 0 to 255 and -128 to 127 respectively. The only difference between byte and sbyte is that byte can not carry signed values and sbyte can.
27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 |
Byte
Short and ushort occupies two bytes in the memory and it ranges from -32768 to 32767 and 0 to 65535 respectively. The only difference between short and ushort is that short can carry signed values and ushort can not.
27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 |
215 | 214 | 213 | 212 | 211 | 210 | 29 | 28 |
Short
Int and uint occupies four bytes in the memory and it ranges from -2147483648 to -2147483648 and 0 to 4294967295 respectively. The only difference between int and uint is that int can carry signed values and uint can not.
27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 |
215 | 214 | 213 | 212 | 211 | 210 | 29 | 28 |
223 | 222 | 221 | 220 | 219 | 218 | 217 | 216 |
231 | 230 | 229 | 228 | 227 | 226 | 225 | 224 |
Int
Table given below give the list ranges and bytes occupied by the variable of different type:
Data Type | Size in Bytes | | |
sbyte | 1 | -128 | 127 |
byte | 1 | 0 | 255 |
short | 2 | -32768 | 32767 |
ushort | 2 | 0 | 65535 |
int | 4 | -2147483648 | 2147483647 |
uint | 4 | 0 | 4294967295 |
long | 8 | -9223372036854775808 | 9223372036854775807 |
ulong | 8 | 0 | 18446744073709551615 |
double | 8 | -1.79769313486232E+308 | 1.79769313486232E+308 |
decimal | 16 | -79228162514264337593543950335 | 79228162514264337593543950335 |
In the same way .Net also gives string data type to store alphanumeric data. String occupies 20 plus bytes means initially it occupies 20 bytes but when maximum value of its range reaches it will increases its bytes. If we store numeric value in string type it will not consider it as numeric, it will be considered as string (but .Net gives various methods to convert string in integer and other numeric value types).