C # Getting Started Classic (fifth edition) learning notes (i)

Source: Internet
Author: User

---------------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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.