Tuesday, January 26, 2010

Data Type Range: Integer

I've been developing C# for so many years. As I work through my certification (a goal for a very long time :D) I always miss the very basic things about C#. For example, I could not really differentiate the Integer data types with their range and size. So this post serves a my own reminder for that.

  • sbyte - based on System.SByte
    • 8-bit signed integer between -128 and 127
  • byte - based on System.Byte
    • 8-bit integer between 0 and 255
  • short - based on System.Int16
    • 16-bit integer between -32,768 and 32,767
  • ushort - based on System.Int16
    • 16-bit unsigned integer between 0 and 65,535
  • int - based on System.Int32
    • 32-bit integer between -2,147,483,648 and 2,147,483,647
  • uint - based on System.Int32
    • 32-bit unsigned integer between 0 and 4,294,967,295
  • long - based on System.Int64
    • 64-bit integer between -9,223,372,036,854,775,808 and 9,223,372,036,854,775,807
  • ulong - based on System.Int64
    • 64-bit unsigned integer between 0 and 18,446,744,073,709,551,615

We have to take note on the memory requirement and performance upon using these data type as we code. int requires twice as much storage of space (4 bytes) than short (2 bytes).

But as a recommendation we have to use int or long because they are more efficient than byte and short because .Net represents numbers as a 32-bit or a 64-bit values. Unless you have a valid concern about memory usage, then you could use the specific data type for your needs.


No comments:

Post a Comment