In the learning phase developer are not much aware of the difference between primitive, FCL (framework class library), reference, and value types. This cause bugs and performance issues into the code. In this article, I would like to expose the different behavior of integer type.
int
- It is a primitive data type defined in C#.
- It is mapped to Int32 of FCL type.
- It is a value type and represent System.Int32 struct.
- It is signed and takes 32 bits.
- It has minimum -2147483648 and maximum +2147483647 capacity.
Int16
- It is a FCL type.
- In C#, short is mapped to Int16.
- It is a value type and represent System.Int16 struct.
- It is signed and takes 16 bits.
- It has minimum -32768 and maximum +32767 capacity.
Int32
- It is a FCL type.
- In C#, int is mapped to Int32.
- It is a value type and represent System.Int32 struct.
- It is signed and takes 32 bits.
- It has minimum -2147483648 and maximum +2147483647 capacity.
Int64
- It is a FCL type.
- In C#, long is mapped to Int64.
- It is a value type and represent System.Int64 struct.
- It is signed and takes 64 bits.
- It has minimum –9,223,372,036,854,775,808 and maximum 9,223,372,036,854,775,807 capacity.
Note
- A number of developers think that int represents a 32-bit integer when the application is running on a 32-bit OS and it represents a 64-bit integer when the application is running on a 64-bit OS. This is absolutely wrong.
- In C# int is a primitive data type and it always mapped to System.Int32 whether the OS is 32-bit or 64-bit.
No comments:
Post a Comment