SEARCH C# PROGRAMMING CODES HERE

Variables in C#

Variables
A variable can be compared to a storage room and is essential for the programmer.
For each variable in C# has a specific type, which determines the size and layout of the variable's memory the range of values that can be stored within that memory and the set of operations that can be applied to the variable.
Variables are initialized with an equal sign followed by constant expression in C#.
<data type> <name>;
The data type must be a valid C# data type including char, int, float, double, or any user-defined data type, and variable name may consist of one or more identifier names separated by commas as shown below.

int x, y, z;

char c, ch;
float f, amount;
double d;

We use the following syntax to define a variable in C#

int  x = 10;
float Float = 1f;
bool Boolean = true;
string Name = "Rohit";
char Char = 'a';
double Double = 5.25;

Apart from this, you can initialize a variable at the time of declaration as shown below.

For Example
int a=10, b=15,c=0;  
c=a+b;
Output =25

No comments:

Post a Comment