C# Variables
Variables are
containers for storing data values.
In C#, there are different
types of variables.
- ·
Int
- stores integer (whole numbers) such as 123 or -123.
- ·
Double-
stores floating point numbers such as 19.99 0r -1.99.
- ·
Char-
stores single character ‘a’, ’C’.
- ·
String-
stores text “Hello World”.
- ·
Bool
– stores values with two sets, true or false.
To create a
variable, you must specify the type and assign it a value.
Syntax:
Type Variable Name
= value;
Where , typeàData Type (such as int or string),
Variable NameàVariable Name is the name of the variable (such as x
or name),
= (equal sign)àthe equal sign is used to assign value to the
variable.
Note: so
many ways to declaring variables.
Step1: To Create
variable that should store a Text
EXAMPLE:
Create a variable
called name of the type string and assign it the value “porkodi”
Step2: To Create
variable that should store a Number.
EXAMPLE:
Create a variable
called name of the type int and assign it the value 15.
Step3:To declare
variables using constants.
CONSTANT:
You can using the
constant keyword, this will declare the variable as “constant”, which means unchangeable
and read only.
EXAMPLE:
DECLARE A MANY
VARIABLES:
To declare more
than one variable of the same type, use a comma separated list:
EXAMPLE:
C# IDENTIFIER:
All C# variables
must be identified with unique names.
These unique name
are called Identifier.
Identifier can be
short names like(x/y).
EXAMPLE: