Game Development Reference
In-Depth Information
GraphicsDevice.Clear(gameTime) . In order to do this, each kind of information used in
a program is of a type . There are many types in C#, you can even make your own
types!
4.2.2 Declaration and Assignment of Variables
Next to the type of information that needs to be stored, the compiler also needs to
know what name we are going to use in the program when we want to use or modify
this information. Together, the type and the name form the declaration .Thisisan
example of a declaration:
int red;
In this example, int is the type of the location in memory, and red is the name used
to refer to that place in memory. The type name is an abbreviation of integer and
you can use this type to store a whole number. In programming languages, a place
in memory with a name and a type is called a variable . So from now on, we will
be talking about the variable red . After this declaration, we can visualize what the
memory looks like:
Now that we have told the compiler that some place in memory will be used
for storing a number, and we call this place 'red', we can use that variable in our
program to store a number in. Variables are given a value with an assignment in-
struction . This is done as follows:
red = 3;
The memory now looks like this:
The assignment instruction consists of the following parts:
the name of the variable that should be assigned a value;
the '=' sign;
the new value of the variable
a semicolon
We can recognize the assignment instruction by the equals-sign in the middle. How-
ever, it is better to think of this sign as 'becomes' rather than 'equals' in C#. After
all, the variable is not yet equal to the value to the right of the '=' sign, it becomes
that value after the instruction is executed. The syntax diagram describing the as-
signment instruction is given as follows:
Search WWH ::




Custom Search