C # Study Notes (2) -- variables and expressions,
Ps: using these two keywords can easily collect the header file (although VS has integrated this function =)
Static void Main (string [] args) {int a; string s; a = 17; s = "\" a \ "is"; Console. writeLine ("{0} {1 }. ", s, a); Console. readKey ();}
The declaration, assignment, and output operations are completed here.
A. Statement
int a;string s;
Declare an integer and a string variable
B. Assignment
a = 17;s = "\"a\" is";
The assignment of the first integer variable is easy to understand, and then the assignment of the following string. in C #, if you want to assign a variable a literal value, you need to use the Escape Character '\'. As shown above, it is different from C and C ++, but the default character is used first.
C. Output
Console.WriteLine("{0} {1}.", s, a);
Here {0} {1} is a placeholder, that is, replace {0}, {1} with s and a in order }.
2. Naming rules
UserName = Console. ReadLine ();
2. Value assignment
1. Operators
3. Operator priority
It is the same as C and C ++.
4. namespace
(1) Definition
PS: The namespace generally uses the PascalCase naming method.
(2) nested Definition
Even if the names of variables are the same, as long as they are in different namespaces, they represent different variables. Therefore, we use namespaces to distinguish variables with the same name.
(3) using statement
In this way, we can call the variable name of LevelTwo in brackets of LevelOne without adding the LevelTwo. prefix. It is for our convenience. However, when we use this statement for variables with the same name, compilation errors will occur. Therefore, we can use an alias to solve such problems.
For example, when calling LevelOne, we can directly use NameThree. When calling LevelTwo, we can call: LT. NameThree.
Of course, using can also be placed out of all curly braces to become a global statement. In this case, you can use the variable functions in the namespace called by using within the global range without the need to add a prefix.
In the C language, what is the symbol (->) and how to use it?
This is a symbol in the struct pointer. Write a program to explain it, for example:
# Include <stdio. h>
Struct STU // define a struct
{
Int num;
} Stu;
Int main ()
{
Struct STU * p; // defines a struct pointer.
P = stu; // p points to the struct variable stu.
Stu. num = 100; // attaches an initial value to the struct member num.
Printf ("% d", p-> num); // output the num value in stu
Return;
}
As you can see, the-> method is to reference the variable in the struct !!
Format: p-> struct member (such as p-> num)
The function is equivalent to stu. num or (* p). num.
I don't know. You don't understand, and don't understand call me. O (∩ _ ∩) O ~
Hope to adopt it.
In the C language, what is the symbol (->) and how to use it?
This is a symbol in the struct pointer. Write a program to explain it, for example:
# Include <stdio. h>
Struct STU // define a struct
{
Int num;
} Stu;
Int main ()
{
Struct STU * p; // defines a struct pointer.
P = stu; // p points to the struct variable stu.
Stu. num = 100; // attaches an initial value to the struct member num.
Printf ("% d", p-> num); // output the num value in stu
Return;
}
As you can see, the-> method is to reference the variable in the struct !!
Format: p-> struct member (such as p-> num)
The function is equivalent to stu. num or (* p). num.
I don't know. You don't understand, and don't understand call me. O (∩ _ ∩) O ~
Hope to adopt it.