Information Technology Reference
In-Depth Information
Variables
A general-purpose programming language must allow a program to store and retrieve data.
￿A variable is a name that represents data stored in memory during program execution.
￿C# provides four categories of variables, each of which will be discussed in detail. The
four types are as follows:
-Local variables
-Fields
-
Parameters
-
Array elements
Variable Declarations
A variable must be declared before it can be used. The variable declaration defines the variable,
and accomplishes two things:
￿
It gives the variable a name.
￿
It allows the compiler to allocate memory for it.
A simple variable declaration requires at least a type and a name. The following declara-
tion defines a variable named var2 , of type int :
Type
int var2;
Name
For example, Figure 3-11 represents the declaration of four variables and their places on
the stack.
Figure 3-11. Value type and reference type variable declarations
Search WWH ::




Custom Search