---------------Variables and Expressions---------------
Assignment operators:
+=;-=;*=;/=;%=
For example:
I+=j equivalent to I=i+j
I-=j equivalent to I=i-j
And so on
Bitwise operators:
&--and |--or ^--xor ~--inversion >>--right shift <<--left shift
For example:
A binary representation of 5 is 00000101
A binary representation of 9 is 00001001
5&9 = 00000101&00001001 = 00000001 = 1
5|9 = 00000101|00001001 = 00001101 = 13
5^9 = 00000101^00001001 = 00001100 = 12
-~00000101 = 11111010 = 6
9>>2 = 00001001>>2 = 00000100>>1 = 00000010 = 2
9<<2 = 00001001<<2 = 00010010<<1 = 00100100 = 36
---------------Process Control---------------
Ternary operators:
<test>? <resultIfTrue>: <resultIfFalse>
Switch
Multiple case can be stacked, for example:
Switch (<testVar>)
{
Case <comparisonvar1>:
Case <comparisonvar2>:
<code to execute if <testVar> = = <comparisonVar1> or
<testVar> = = <comparisonVar2>
Break
...
}
Cyclic interrupts:
break--immediately terminates the loop
continue--immediately terminates the current loop (resumes execution of the next loop)
goto--jumps out of the loop, goes to mark Bits
return--jumping out of the loop machine contains functions
---------------More about Variables---------------
Overflow check:
Checked (expression)
For example:
BYTE B;
Short S = 281;
b = Checked ((byte) s);
Because the maximum value of byte type is 255, it overflows when the explicit conversion of (byte) s is performed, such as checking with chenked (), the program crashes and errors
Unchecked (expression)
Do not check for overflow
Array
One-dimensional array: <basetype>[] <name>
Multidimensional arrays: <basetype>[,] <name> or <basetype>[,,,...,] <name>
Array of arrays: <basetype>[][] <name>
For example:
Int[][] Divisors1to5 = {New int[] {1},
New int[] {to},
New int[] {1,3},
New int[] {1,2,4},
New int[] {1,5}}
foreach (int[] intarray in divisors1to5)
{
foreach (int i in Intarray)
{
Console.Write (i.ToString ());
}
Console.Write ("\ n");
}
Console.readkey ();
String processing:
<string>. ToCharArray ()--You can split a string into an array of single characters
For example:
String myString = "I Love You";
Char mychars = Mystring.tochararray ();
foreach (char c in mychars)
{
Console.WriteLine (c);
}
Console.readkey ();
< String>. PadLeft (<desiredLength>) and. PadRight (<desiredLength>)--the number of spaces to be padded to a specified length
C # Getting Started Classic (fifth edition) learning notes (i)