s

C# variables edit button Edit

author
Rakesh Kumar Sutar | calendar 19 January 2021 | 2073

Introduction

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.

Syntax

type variable_name = value; 
or
type variable_names;

Example

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.