Let’s see how to declare and initialize variables in C#.
A variable is a name given to a memory location where the value is stored. These variables have a data type based on the value stored in them.
Syntax for variable declaration: data_type variable_name;
Example for variable declaration: int age;
NOTE: You will get compilation error if you use a variable before assigning an initial value.
To avoid this compilation error, you can assign a default value to the variable at the time of declaration. You can combine variable declaration and initialization in the same line. You assign a value to a variable using = sign.
For example: int age = 20;
Below is sample code:




