C # Nature Theory Chapter III operator and control flow

Source: Internet
Author: User

Operators are generally divided into 3 main categories: Unary operators (positive, negative), two-ary operators (plus, minus, multiply, divide, and subtract) and ternary operators (Condition?consequence:alternative ( Consequence and alternative expression types are identical), their operands are one, two, and three respectively.

If Eternity brackets Add code readability.

To stitch a string with a format-compliant instead of an addition operator.

The two-letter distance can be subtracted by the char type.

Float has seven-bit accuracy:

Error code:

float N1 = 0.987654321;

  

Correct code :

    float 0.987654321F ;    Console.WriteLine (n);  0.9876543    
    float 987654321; // you can do it without F .     Console.WriteLine (n);  9.876543E+8

Binary floating-point types internally actually store binary fractions instead of decimal fractions. Therefore, a decimal that is not an integer power of 2 can not be accurately represented by a binary floating-point number. In fact, a 16-bit float is used, and the denominator is expressed as a fraction of the power of the 2 whole number. Double A 15-bit valid number.

    140.6F ;    Console.WriteLine (n);  140.600006103516

Avoid using binary floating-point types when accurate decimal arithmetic operations are required, and decimal floating-point.

    Double 140.63435423524252315 ;    Console.WriteLine (n); //displays: 140.634354235243    Double 140.63435423524242315 ;    Console.WriteLine (n);  140.634354235242

Therefore, avoid using binary floating-point types for equality conditionals. Either determine whether the difference between the two values is within the tolerance range, or use the decimal type.

    floatn =0F; Console.WriteLine (n/0);//displays: Non-digitalConsole.WriteLine (0/0);//error: by constant 0 exceptConsole.WriteLine (0.0/0);//displays: Non-digitalConsole.WriteLine (-1/0);//error: by constant 0 exceptConsole.WriteLine (-1f/0);//displays: Negative InfinityConsole.WriteLine (1F/0);//Displays: Positive Infinity

Compound assignment operators:

1     CharCurrent ='Z';2     intUnicodevalue;3      Do4     {5Unicodevalue =Current ;6Console. Write ("{0}={1}\t", current,unicodevalue);7current--;8} while(current>='a');9Console.read ();

 int  count = 123  ;     int   result;    Result  = Count++; Console. Write (  " {0}\t{1}  "  ,result,count); Console.ReadLine ();  // 123 124  
    int 123 ;     int result;     = + +count;    Console. Write ("{0}\t{1}", Result,count);    Console.ReadLine (); // 124     124

The result of the prefix operator is the value after which the variable is incremented, and the result of the suffix operator is the value before the variable is incremented.

Do not use constants to represent any values that may change in the future.

Empty join operator (?? If it is null before, it represents the last expression.

X?? Y?? Z

Do not use the shift operator as a multiplication method.

Bitwise logical Operator:& | ^ No "short circuit evaluation":& |

Bitwise assignment Operator: &= |= ^=

Take the inverse operator (~)

Control Flow:

Do/while is similar to a while loop, except that it loops at least once.

foreach Loop:

foreach inch collection)    Statement

Do not use continue as a jump statement to exit the switch section.

Jump statement: Break.

Preprocessing directives: called at compile time

#region

#endregion

C # Nature Theory Chapter III operator and control flow

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.