Let's talk about the basics of Web front-end today.
Data Operation Case Study: Copy of Variable Value-------copy data to another variable
Self-increment or decrement of variables-increase or decrease on the basis of the original
Eg:int a=1;
a=a+5------Self-increment
a=a-4-------Self-reduction
Operation of multiple data-at least 2 or more data
( note the return type of each step operation )
eg:1, int x=1,y=2;
X=x+y
X=x-1
Where: X=x+y and x=x-1 can be combined to write as--x=x+y-1
Let's look at a few more examples below:
2, int x=1+1.3+2;
int x=1+ "1" +2;
Do you think the code written above is correct? Why?
The answer is not correct. Because the int type is an integer, his return result must also be of type int, but 1.3 is a decimal, and double cannot be assigned to int, so it cannot be converted to an int type. Similarly, "1" is of type string and cannot be converted directly to type int, so the following code is also wrong. So how do you change it right? Either the 1.3 and the "1" are converted to integers, or the preceding int is changed to double and string type correctly.
Variable value Exchange--requires a third amount to implement
First look at this code: int x=1,y=2;
X=y;
Y=x: Do you think the above code can be implemented?
This is definitely not possible, because the above code it is expressed by the meaning is to assign 2 to X, then the current x is no longer 1, but 2, and then assign the x=2 to Y, when Y is 2, which obviously has changed the original value, is unable to achieve its desired effect. If you add a new volume Z to the above code to achieve the intermediate transition, you can achieve the desired effect as follows:
int x=1,y=2;
Z=x;
X=y;
Y=z: That's the right thing to write.
Input statement: Get user input in the console
Function: Program pauses execution, waits for user input (blinking cursor)
Code writing: Console. Readline ();--string type
return type: String type
Eg:string S=console.readline ();
--Pause the program and wait for input
--Press ENTER when the input is complete to get the input string
--Keep the string in the variable s
Type conversion: Converting a type of data to another type of data
A, any type of →string
Conversion code: The data to be converted. ToString (); ————————[data to be converted: Data or variable to be converted;. Tostring (); is a fixed notation]
return type: string
Eg:int a=10;
string B=a; This is a wrong code. Why is it?
Because int cannot assign a value to a string in this code. Change the following code to: String b=a.tostring (); it's right.
Conversion of B, int and double
Principle: Numeric types with a small range of values ———— numeric types with a large range of values (implicit conversions: no extra code required)
Numeric types with large range of values ———— numeric types with a small range of values (Explicit conversions: additional code required)
Implicit conversions: Double Value range >int range
Explicit conversions: Eg:double a=3.14;
int B=a error.
It should be int b= (int) A {The question comes, here the double is a decimal, and int is an integer, is int b=3.14? Of course not, because the int type can only be rounded, so here int B can only be equal to 3, the number of the decimal part should be discarded, it cannot be rounded. Therefore, an explicit conversion can cause data loss. }
C, string→ numeric type
String--int:int.parse (string to be converted); return type: int
String--double:double.parse (string to be converted); return type: Double
Eg:string str1= "1", str2= "Number 1";
int A=int.parse (STR1); —————— String→int
Double B=double.parse (str2); ———— string→double
A=int.parse (STR2); —————— string→int X cannot convert "number 1" to int
B=double.parse (STR2); ———— string→double X cannot convert "number 1" to double
A=double.parse (STR1); ———— string→double X cannot assign double type data to int type
Escape character: Write a slash (\) in your code that is used to change the meaning of the character after the slash
Common: \ "→ double quotes \ ' → single quote \n→ newline character \t→ tab \\→ slash \
Eg:string pth= "C\windows\iis.log"; X
String pth= "C\\windows\\iis.log"; or string [email protected] "C\windows\iis.log"; "@: Indicates that the escape character does not appear in the next string"
Console.Write ("You're good"); → You
Good
Console.WriteLine ("\ t you \ t good") → Hello
Number type usage principles: 1, for real numbers with high computational accuracy, use decimal
2, for the use of memory requirements of the software, as far as possible to ensure that the scope of the use of less than the type of placeholder
3, if not the above requirements, integers with int, real number with double
Code comments: Use a few descriptive statements to make your code easier to read and understand
Note content, without any substantive function, does not participate in compilation, only exists in the source code
Writing code: Single-line comment--//comment content
Multiline comment--/* Comment content */
Document comments
When do I use annotations?
Code is difficult to understand, the code is very complex, the code is large, in team development, there will be other people to read your code
Errors and debugging in the software:
A, compile error (cause source code cannot compile): Error found--View the Error list in VS--menu bar view → select Error List
Resolve errors--make appropriate changes based on error prompts
Error features-easy to find, easy to modify
B, run error (Error in operation): Errors found--run in debug mode, and run to the error statement
Resolve errors--make appropriate changes based on error prompts
Error characteristics-difficult to find, difficult to modify
C, logic error (running result and expected difference): Found error--carefully check the results of the operation to see whether it is consistent with the expected
Resolve errors--Use the VS breakpoint debug to check the execution results of each step
Error characteristics-very difficult to find, very difficult to modify
Expressions for operators
Operator: an operator, a symbol for an operation that acts on one or more operators (operators: data that participates in the operation)
Eg:string a= "$" +z*b/c//A statement in the main function
Category: Quantity: Unary operator, two-ary operator, ternary operator
Functions: Arithmetic operators, logical operators, bitwise operators, other
Common parentheses (): function: type conversion, change Order of operations, function call
Arithmetic operators: + 、-、 *,/,%, + + 、--
++:A, variable name ++--1, calculated return result is the same as the variable; 2. Increment the value of the variable by 1
B, + + variable name--1, calculate return result, +1;2 variable value, increment value from 1
--:A, variable name--—— 1, the calculated return result is the same as the variable, 2, the value of the variable is reduced by 1
b 、--the variable name--1, calculates the return result, -1;2 the value of the variable, and subtract the value of the variable by 1
Order of Operation: + + 、--、 →*/%→+-
Eg:int x=1
Calculate x=x+x++-x--*++x/--x%x
Get: x=1+1-2*2/1%1=2-0=2
Assignment operators: =, + =,-=, *=,/=,%=
eg:x+= operation code equivalent to x=x+ (Operation code)
Return result: Same as variable value
logical operators: = =,! =, >, >=, <, <=, &&, | | 、!、
Return result: BOOL type →true or FALSE (bool denotes true and false two state values range: TRUE or FALSE)
eg:== int a=1,b=2;
Boolc=a==b→a equals B? →false (same as! =, >, >=, <, <=)
&& two bool types for operation, results: True True, others false
int a=1,b=2;
BOOL C=a!=b; →1 Not equal to 2
BOOL D=a>b
BOOL E=c&&d
False
|| two bool types for operation, operation result: false false is false, other is true
int a=1,b=2;
BOOL C=a!=b; →1 Not equal to 2
BOOL D=a>b
BOOL E=c| | D
True
! Negation of a bool type data, the data is true, the result is false, the data is false, the result is true
int a=1,b=2;
BOOL C=a!=b;
BOOL D=!c→c is True
False
Three-mesh operators:
Write: Operand 1? Operand 2: Operand 3 (operand 1 is type bool, symbol is in English mode, operand 2, operand 3 is any type, but must be the same)
Returns the result: if the operand 1 is true, the operand 2 is the return result; if the operand is false, the operand 3 is returned as the result of
Eg:int a=3;
int b=a%2; →b=1
BOOL c=b==0; →c false
String d=c? " Even ":" Odd ";
Console.WriteLine (d); →d is an odd number
Bitwise operators: Used for binary operations on numbers
Expression: A meaningful statement with at least one operand and operator in the statement
Each expression has a return type
Each expression can be operated with other expressions (except for viod-, no results returned), as long as the type meets the requirements
Operator Precedence
Common scenarios that use multiple operators
Assignment operation: Last Run Forever
Mathematical operations: In the Order of mathematics (first run the parentheses, there are nested from inside to outside, and then run multiplication for redundancy; last addition minus)
Web front-End Learning Basics 3