A Variable is the name given to a memory location holding a particular type of data. so, each variable has associated with it a data type and a value type.
|Integral types||sbyte, byte, short, ushort, int, uint, long, ulong, and char|
|Floating point types||float and double|
|Boolean types||true or false values, as assigned|
|Nullable types||Nullable data types|
C# also allows defining other value types of variable such as Enum and reference types of variable such as class , which we will cover in subsequent chapters.
Syntax for variable definition in c# is –
Here, data_type must be a valid c# data type including char, int, float, double, or any user – defined data type, and variable_list may consist of one or more identifier names separated by commas.
char c, ch;
float f, salary;
You can initialize a variable at the time of definition as –
int i = 100;
Variables are initialized (assigned a value) with an equal sign followed by a constant expression. The general form of initialization is –
Variable_name = value;
Variables can be initialized in their declaration. The initializer consists of an equal sign followed by a constant expression as –
<data_type> <variable_name> = value;