Variable
1> declaring a variable requires specifying the type and variable name: <type> <name>
Type: Indicates what types are used to store data
Name: This type is stored
Example: (each declaration is a statement with a statement; (semicolon) end)
int Age ; int HP; string name;
As follows:
2> compliance with naming conventions makes the program structure clearer and easier to read.
Specification: The first word begins with a lowercase letter, followed by the name of the first uppercase variable for each word in accordance with the Camel name Method (Hump nomenclature). The first letter is lowercase, and the first letter of each word is capitalized.
Examples are as follows:
Two: Character 1> char with string:
Char represents a character, a letter, a number, a @#¥%......&* (), a Chinese character
String is an array of char and is a collection of characters
2> Escape Character:
Escape character is a character with special function
If we do not want to identify the escape character in the string, you can precede the string with an @ sign (except for the double quotation marks other escape characters are not recognized)
Example of two functions of the 3> @ character:
1, the default one string definition is placed on a line, if you want to occupy multiple lines
2, the path is represented by a string
"C:\xxx\xx\xxx.doc"
Use @ "C:\xxx\xx\xxx.doc" to read more
The function of the Unicode value of the 4> character:
Unicode is a 16-digit number that represents the number in memory in which this character is stored
You can also use Unicode to represent an escape character (\u plus hexadecimal value)
"I\ ' s kmart!"
"I\u0027s kmart!"
5> Declaration and assignment
Declaration of a variableint age;
Assigning values to variablesage = 54;
The Declaration and assignment of a variable can be placed in a statement < equivalent to initialization >
int age = 54;
We can declare multiple variables of the same type using a single statement
String name1,name2;
In a multi-variable declaration, you can follow the variable followed by =, initialize one of the variables or some, all of the variables.
Precautions:
Variables must be initialized before use, how to determine whether a variable is used, but when you take something from the box (memory) of the variable, when you want to use the variable, the initialization is to put something into the box to get it. The first time a variable is assigned, it is initialized.
6> expression:
Combining variables with literals and operators is an expression.
Classification of operators:
Unary operators handle one operand
Binary operators handle two operands
Ternary operators handle three operands
7> Mathematical operators:
Add, subtract, multiply, divide
Self-Study C # The second variable and expression