Saturday, February 16, 2019 15:15

Type modifiers

As you already learned, C# offers 6 base numeric types (int, byte, char, float, double, decimal). In order to explain type modifiers, you should remember that a type defines a set of values that a variable can store and the kind of operations that the program can perform on them. You should also remember that int variable types can store only values between -2,147,483,648 and 2,147,483,647, a char between 0 and 65,535, etc.

To help you modify the interval in which a variable can store a value, C# offers a few type modifiers, like unsigned, short, longetc.

Basically, you should not concern yourself with these kind of variables, since they are only a legacy from the old age of computers, when memory space was counted in Kb and every bit counted, so you needed to manipulate the memory used by your programs pretty efficient. In those days, if you wanted to store an integer that would be out of the normal range, and you were sure it will only hold positive values, you would use a “unsigned integer”, or uintwhich was using the sign bit also for storing a relevant value.

As a rule, stick as much as possible to the basic types C# offers. You will have less headaches and you will less likely find yourself in an overflow situation.



Tags: , ,

Leave a Reply