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#:
- Must begin with a letter or an 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.