The C# language fundamentals ( II ) Po Feng, Tsai.
-
Upload
buddy-williams -
Category
Documents
-
view
217 -
download
0
Transcript of The C# language fundamentals ( II ) Po Feng, Tsai.
![Page 1: The C# language fundamentals ( II ) Po Feng, Tsai.](https://reader030.fdocuments.in/reader030/viewer/2022032806/56649f045503460f94c18e9a/html5/thumbnails/1.jpg)
The C# language fundamentals
( II )
Po Feng, Tsai
![Page 2: The C# language fundamentals ( II ) Po Feng, Tsai.](https://reader030.fdocuments.in/reader030/viewer/2022032806/56649f045503460f94c18e9a/html5/thumbnails/2.jpg)
Switch statements
An alternative to nested ifs Similar to Matlab
![Page 3: The C# language fundamentals ( II ) Po Feng, Tsai.](https://reader030.fdocuments.in/reader030/viewer/2022032806/56649f045503460f94c18e9a/html5/thumbnails/3.jpg)
![Page 4: The C# language fundamentals ( II ) Po Feng, Tsai.](https://reader030.fdocuments.in/reader030/viewer/2022032806/56649f045503460f94c18e9a/html5/thumbnails/4.jpg)
The goto and break keywords The switch statement
Fall through Goto
Move to another address with specified label Create a label and the goto the label
Break Jump out of the switch statement
Averting from using goto is strongly suggested Complicating your codes
![Page 5: The C# language fundamentals ( II ) Po Feng, Tsai.](https://reader030.fdocuments.in/reader030/viewer/2022032806/56649f045503460f94c18e9a/html5/thumbnails/5.jpg)
Fall through you cannot fall through to the next ca
se if the case statement is not empty
![Page 6: The C# language fundamentals ( II ) Po Feng, Tsai.](https://reader030.fdocuments.in/reader030/viewer/2022032806/56649f045503460f94c18e9a/html5/thumbnails/6.jpg)
Loops The while loop
Example
![Page 7: The C# language fundamentals ( II ) Po Feng, Tsai.](https://reader030.fdocuments.in/reader030/viewer/2022032806/56649f045503460f94c18e9a/html5/thumbnails/7.jpg)
Exercise 7 Please try to use the while loop to pri
nt the following message * ** *** **** *****
Debugger
![Page 8: The C# language fundamentals ( II ) Po Feng, Tsai.](https://reader030.fdocuments.in/reader030/viewer/2022032806/56649f045503460f94c18e9a/html5/thumbnails/8.jpg)
Loops The do…while loop
Example
![Page 9: The C# language fundamentals ( II ) Po Feng, Tsai.](https://reader030.fdocuments.in/reader030/viewer/2022032806/56649f045503460f94c18e9a/html5/thumbnails/9.jpg)
Loops The for loop
Example
remainder
![Page 10: The C# language fundamentals ( II ) Po Feng, Tsai.](https://reader030.fdocuments.in/reader030/viewer/2022032806/56649f045503460f94c18e9a/html5/thumbnails/10.jpg)
Exercise 8
Please try to use the for loop to print the following message * ** *** **** *****
![Page 11: The C# language fundamentals ( II ) Po Feng, Tsai.](https://reader030.fdocuments.in/reader030/viewer/2022032806/56649f045503460f94c18e9a/html5/thumbnails/11.jpg)
Continue & Break
The continue statement causes the loop to return to the top and continue executing
The break statement causes the loop to stop and jump out of executing block
Example
![Page 12: The C# language fundamentals ( II ) Po Feng, Tsai.](https://reader030.fdocuments.in/reader030/viewer/2022032806/56649f045503460f94c18e9a/html5/thumbnails/12.jpg)
Alarm system (3-15)
![Page 13: The C# language fundamentals ( II ) Po Feng, Tsai.](https://reader030.fdocuments.in/reader030/viewer/2022032806/56649f045503460f94c18e9a/html5/thumbnails/13.jpg)
Exercise 9
Please implement a multiplication table (3x9) with any of the loops mentioned above
![Page 14: The C# language fundamentals ( II ) Po Feng, Tsai.](https://reader030.fdocuments.in/reader030/viewer/2022032806/56649f045503460f94c18e9a/html5/thumbnails/14.jpg)
The ternary operatorUsage
Example
![Page 15: The C# language fundamentals ( II ) Po Feng, Tsai.](https://reader030.fdocuments.in/reader030/viewer/2022032806/56649f045503460f94c18e9a/html5/thumbnails/15.jpg)
Preprocessor Directives
Before your code is compiled, another program called the preprocessor runs and prepares your program for the compiler begin with the pound sign (#) Usually for debugging purpose
![Page 16: The C# language fundamentals ( II ) Po Feng, Tsai.](https://reader030.fdocuments.in/reader030/viewer/2022032806/56649f045503460f94c18e9a/html5/thumbnails/16.jpg)
Example 1
![Page 17: The C# language fundamentals ( II ) Po Feng, Tsai.](https://reader030.fdocuments.in/reader030/viewer/2022032806/56649f045503460f94c18e9a/html5/thumbnails/17.jpg)
Example 2
![Page 18: The C# language fundamentals ( II ) Po Feng, Tsai.](https://reader030.fdocuments.in/reader030/viewer/2022032806/56649f045503460f94c18e9a/html5/thumbnails/18.jpg)
#region
Used to mark off areas of code and collapse them Paired with #endregion Additional information can be attached ri
ght after the label
![Page 19: The C# language fundamentals ( II ) Po Feng, Tsai.](https://reader030.fdocuments.in/reader030/viewer/2022032806/56649f045503460f94c18e9a/html5/thumbnails/19.jpg)
Click here
Click here