Sunday, June 16, 2019 05:07

Variable types

When you declare variables in your programs, you must indicate to the compiler the type and the name of the variables. There are many variable types and derivations of them. A type defines the amount of data a variable can store, and the set of operations the program can perform on those data.

C# accepts the following base types:

Additional Information

There are a lot of other derived types of these variables, that are not used as much, or they are used in special cases. While it is unlikely you will be using them any time soon, you should take a look over them to familiarize yourself with their keyword names

The u in some keywords stands for unsigned, meaning that the variable uses the sign bit to further store relevant digits, in which case it can store only positive values or 0.

 

EXERCISES
1. Declare several variables by selecting for each one of them the most appropriate of the types sbyte, byte, short, ushort, int, uint, long and ulong, in order to assign them the following values: 52,130; -115; 4825932; 97; -10000; 20000; 224; 970,700,000; 112; -44; -1,000,000; 1990; 123456789123456789.

Solution


Look up the above variable types value ranges and select the appropriate ones for the given examples.

Comments

comments

Tags: ,

Leave a Reply