C # basic notes (Day 5 ),

Source: Internet
Author: User

C # basic notes (Day 5 ),

1. for Loop
Forward-order Loop
For + tab
For (int I = 0; I <length; I ++)

Inverted Loop
Forr + tab
For (int I = length-1; I> = 0; I --)

2. daffodils
This hundred-bit hundreds of cubes + Ten cubes + cubes = this hundred-bit
100 bits: num/
Ten: num % 100/10
Single digit: num % 10

3. parse type conversion
If convert fails to be converted, an exception is thrown.
It basically calls parse.

4.int. TryParse

Int. Tryparse is a method

Try to convert a string to the int type.

1 // set an int type num with the initial value 02 int num = 0; 3 // use the Bool type to receive and use TryParse to try to convert "123abc" to the int type and save the Conversion Result to num. 4 bool B = int. tryParse ("123abc", out num); 5 // If the conversion is successful, B is true. If the conversion fails, B is false6 Console. writeLine (B); 7 // The converted value is successfully converted, and the conversion failed is the initial value of num 8 Console. writeLine (num); 9 Console. readKey ();

 

6. continue
Continue is generally used in combination with If
When a condition is met, return to the cyclic condition to judge
Difference from break
Continue: You can choose to continue or not execute the loop. execution or not execution depends on whether the loop condition is true or not.
Break: jump out of the loop directly

7. Prime Number/prime number
The number that can only be divided by 1 and the number itself. The minimum prime number is 2.

8. Ternary expressions
Syntax:
Expression 1? Expression 2: expression 3;
Int max = A> B? A: B;

Expression 1 is generally a relational expression.
If expression 1 is true, the value of expression 2 is the value of the entire ternary expression.
If the value of expression 1 is false, the value of expression 3 is the value of the entire ternary expression.
Note: The result type of expression 2 must be consistent with the result type of expression 3, and must be consistent with the result type of the entire ternary expression.


9. Random Number
Random r = new Random ();
Int number = r. Next (1, 11 );
Generate 1-10 numbers

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.