VARIABLE DECLARING IN C#:-
A variable is a location in the memory that has a name and
contains a value. The value could be a integer, such as 27, a decimal, such as
6.35, or a character, such as L. a variable is associated with data type that
defines the type of data, which can be stored in a variable. For example, a
variable called TennisplayerName will ideally store characters, whereas a
variable called high_score will store numbers. A program refers to a variable
by its name.
NAMING OF VARIABLES IN C#:
The following rules are used in the naming of variable in
c#:-
1.
Must begin with a letter or a underscore('_'),
which may be followed by a sequence of letters, digits (0-9) or underscores.
The first character in a variable name cannot be a digit.
2.
Should not contain any embedded spaces or
symbols such as ? ! @ # + % $ () [] {} .,;:'”. however, an underscore can be
used whenever a space is required, like high_score.
3.
Must be unique, For example, to store four
different numbers, four unique variable names need to be used. Uppercase
letters are considered distinct from lower-case letters.
4.
Can have any number of character.
5.
Keywords cannot be used as variable names. For
example, you cannot declare a variable named class because it is keyword in c#.
FOR EXAMPLE:-
Game_level
High_score
This_variable_name_is_very_long
The following are the invalid variable names:-
#score
2stank.
NOTE:-
c# is a CASE-SENSITIVE language. This means that the variable
TennisPlayerName is not the same as the variable tennisplayername.
DECLARING AND
INITIALIZING VARIABLES:-
you can declare and initialize variables by using the
following syntax:
<data-_type><variable_name>=<value>;
In the preceding syntax, the <data_type> represents the
kind of data types that will be stored in a variable and <value>
specifies the value that needs to be stored in a variable.
Consider the following statement of variable declaration:
int age;
The preceding statement declares that variable age of the int
data type and initializes the variable with the value 0. the int data type is
used to store numeric data.
Consider the following statement:
char choice=”Y”
The data type represents the kind of data will be store in a
variable.
Previous post is:- WHAT IS C#
next post is:- DATA TYPES IN C#
PLEASE IF YOU HAVE ANY DOUBT, PLEASE COMMENT IT BELOW THE POST.
0 comments:
Post a Comment