Home To Know Codes C# Variables

C# Variables

359
1
SHARE
C# Variables

Variable is a basic concept of C#. Variable is a computer memory location that is reserved for storing the data used by the program or application. Each variable is given a name, assigned a value and type of value by a programmer. By the help of variable value may be read and change.

Variable must be declared as a particular type such as integer, a character or a string. Variable type can not be change but value can casted in another type. This concept is known as casting. The following example declares an integer variable:

int rate;

Initialize a variable using the assignment operator (=)

int rate = 10;

New value given to variable as a requirement:

int rate = 10; // old value
int rate = 24; // assign new value

Constant variables

A constant is similar to a variable in that it provides a named location in memory to store a data value. Constants differ in one significant way in that once a value has been assigned to a constant it can not subsequent be changed.

Constants are particularly useful if there is a value which is used repeatedly throughout the application code. Rather then use the value each time. It makes the code easier to read if the value is first assignment to a constant which is then referred in the code.

Constant must be initialized at the same time that they are declared and must be prefixed with the const keyword.

Const int rate = 10;

C# defines seven categories of variable

Static Variable

Static Variable Example Input
Static Variable Example Input
Static Variable Example Output
Static Variable Example Output

Instance Variable

Instance Variable Example Input
Instance Variable Example Input

Array Elements

Array Elements Example Input
Array Elements Example Input

Value Parameter

Value Parameter Example Input
Value Parameter Example Input
Value Parameter Example Output
Value Parameter Example Output

Reference Parameter

Reference Parameter Example Input
Reference Parameter Example Input
Reference Parameter Example Output
Reference Parameter Example Output

Output Parameters

Output Parameters Example Input
Output Parameters Example Input
Output Parameters Example Output
Output Parameters Example Output

Local Variable

Local Variable Example Input
Local Variable Example Input

1 COMMENT

Leave a Reply