C# Variables - NetwaxLab

Breaking

Facebook Popup

BANNER 728X90

Tuesday, February 3, 2015

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

Input
Output
  • Instance Variable

Instance Variable
  • Array Elements

Array Elements
  • Value Parameter

Input
Output
  • Reference Parameter

Input
Output
  • Output Parameters

Input
Output
  • Local Variable

Local Variable

----

No comments:

Post a Comment