Declaring Variables Or Objects
A variable is a location in the memory that has a name and contains a value. The value could be an integer, such as 17, a decimal, such as 7.35, or a character, such as 'B'. A variable is associated with a data type that defines the type of data, which can be stored in a object. For example, a object called BatsmanName will ideally store characters, whereas a variable called High_Score will store numbers. A program refers to a object by its name.
The following rules are used for naming variables in C#:
- Should not contain any embedded spaces or symbols such as ? ! @ # % ^ & * ( ) { } [ ] . , ; : " ' / and \. However, an underscore can be used wherever a space is required. Like high_score.
- Can have any number of characters.
- Must be unique. For example, to store four different numbers, four unique variable names need to used. Uppercase letters are considered distinct from lowercase letters.
The following are examples of valid variable variable names:
Level_1
Batsman_Name
You_Want_To_Keep_Long_Name
The following are examples of invalid variable names:
%final_score
3rdrank
Important Note :- C# is a case-sensitive language. This means that the variable Batsman_Name is not the same as the batsman_name.
No comments:
Post a Comment