C# variables Edit

Rakesh Kumar Sutar | 19 January 2021 | 130


A program uses various values that may change during its execution. Variables can store temporarily in the Random Access Memory(RAM) of computer and these values in this part of memory vary throughout the execution and hence another term for this came which is known as Variables. So , a Variable is a placeholder of the information which can be changed at runtime. And variables allows to Retrieve and Manipulate the stored information.


type variable_name = value; 
type variable_names;


char var = 'R'; // Declaring and Initializing character variable
int a, b, c; // Declaring variables a, b and c of int type

Characteristics of Variables

  • name : It must be a valid identifier. In above example, var is a valid identifier.
  • type : It defines the types of information which is to be stored into the variable. In above example char is a type.
  • value : It is the actual data which is to be stored in the variable. In above example ‘R' is the value.

Rules for Naming Variables

  • Variable names can contain the letters ‘a-z' or 'A-Z' or digits 0-9 as well as the character ‘_'.
  • The name of the variables cannot be started with a digit.
  • The name of the variable cannot be any C# keyword say int, float, null, String, etc.