Game Development Reference
In-Depth Information
Creating a constant is a similar process to creating a variable. You use the
keyword const followed by the type (which will be discussed shortly) and the
constant name.
const int valuesmy;
const string firstname;
const int value = 34;
The first example sets up a constant int (number) value called valuesmy . The
second example sets up a string (text) called firstname . Finally, the third
example sets the value 34 as a constant named value .
Understanding Keywords
There are two types of keywords in C#, reserved and contextual. Reserved words
are keywords that you cannot use as variables. These are words that are known
to C# and have a particular use. Contextual keywords are words that are used in
particular circumstances, but can be used at other times.
You have already seen three keywords being used in the previous examples
int , string , and const . When I say that the words are reserved, this means that
the programming language knows that these two words are special and it needs
to treat them in a particular way. You can
'
t create an int variable as follows:
int int;
This is because you can
t use the reserved word int as a variable name. There are
a large number of keywords that you shouldn
'
'
t use; for more information
consult the C# documentation.
Understanding Data Types
The previous examples used int , const ,and string . These are special keywords
that define the type of item that follows the word. For example, the word int
means that the variable after it is of type integer, which means the value that will be
stored in this variable can be between
2,147,483,648 and 2,147,483,647. A const is
a value that never changes, such as a player
-
sbirthdayorrealname.A string data
type, on the other hand, is a number of characters that form a word or sentence.
'
There are a large number of different data types in C#. You should consult
online documentation for a complete list, but Figure 14.3 contains some of the
most common data types.
Search WWH ::




Custom Search