You have selected free tutorial of the Microsoft Corporation for the Microsoft Technology Associate (MTA) :
98-361: MTA: Software Development Fundamentals (C#) : Module 1: Introduction to Programming :
Variables, as the name suggests, refer to terms whose values vary. In other words, they
keep a value that might change or are modified during processing. Following is the
syntax for declaring variables in C#:
where datatype can be int, char, and so on.
For example: int l;
The preceding statement declares an int variable named l. For safety reasons, you cannot use this variable in a program until you initialize it. After you declare it, you can assign a value to the variable using the assignment operator = as shown in the next statement:
l = 50;
You can declare a variable and initialize it simultaneously:
int l = 50;
You can declare and initialize more than one variable of the same data type using a single statement:
int l = 50, b =8;
You can modify the values in the variables l and b while processing.
Reference types—These data types don’t store the value; instead, they store a reference to the value. The class objects, strings, and dynamically created variables are known as reference types because they hold references to blocks of memory and are managed on the heap. The heap is basically all unallocated memory in an operating system. When you declare a variable, the compiler allocates a block of memory to store a corresponding value.