Variables are those special keywords which holds a specific value assigned to them in our program.
Consider the following math equation:
- f(x) = x² + 2x
In this equation, X is the variable and f(x) is the function. In programming we can do the same and assign any value to variables to use them later. Variables can be created simply like this:
<data type> <variable name> = <value> ;
Example:
int myNumber = 5;
- Makes an int variable "myNumber" and stores 5 number in it.
string name = "Waleed";
- Makes a string variable "name" and stores my name in it.
float weight = 44.5;
- Makes a float variable "weight" and stores my weight in it.
We can also dynamically read input from users and assign it to variables too.
Example:
string name = Console.ReadLine();
Function Console.ReadLine() will read line in console what ever we have entered and store it in name variable which has a strng datatype.
No comments:
Post a Comment