Game Development Reference
In-Depth Information
related types. For example, you cannot cast a Color variable to a numerical type such
as float .
All the numerical types are given in the following syntax diagram:
4.2.7 Declaration and Initialization of const Variables
Sometimes, it is useful to explicitly state that a variable will not be changed after
it has been given a value. That way, it is clear to the readers of your program that
this value will stay the same throughout the entire program. Furthermore, if you
accidentally try to change it anyway, the compiler will complain about it. Often,
things like mathematical constants are typically values stored in this way. Have a
look at this example:
const float pi = 3.14159265f;
After this combined declaration and initialization, we are no longer allowed to
change the variable. In other words, if we try to execute the following instruction:
pi = 12.0f;
the compiler will generate an error that it is not allowed to assign a value to the pi
variable because it is a constant.
4.2.8 DiscoWorld: A Changing Background Color
In the previous sections, we talked about different variable types and how to declare
and assign them. We have given several examples of how to declare and assign vari-
ables of type int or double . Next to the numerical types we have discussed there are
many other types in C#. For example, GameTime is also a type and it represents the
game time , in other words: the time that has passed since the game has started. As
 
Search WWH ::




Custom Search