C # Operators

Source: Internet
Author: User

1. Relational operator:< less than, <= small equals, > Greater than, >= large equals, = = equals,! = is not equal.
2. Logical operators:! Logical non, && logic and (two All), | | Logical OR (one of the two matches).
3. Conditional operator: expression 1? Expression 2: Expression 3, expression 1 bit true is return expression 2, otherwise return expression 3. max = A>b? A:B;
4.is operator: Used to check whether the expression is of the specified type, and if so, returns True, otherwise false.
5.+ 、-、 *,/,% corresponds to subtraction per cent.
6. Bitwise operator: The left shift operator (<<) moves the first operand to the left by the number of bits specified by the second operand, the vacated position is 0, and the left shift is equivalent to multiplication. The left shift is equivalent to multiply by 2, the left two is equal to 4, and the left three is the equivalent of multiply by 8. The type of the second operand must be an int or a type that has a predefined implicit numeric conversion to int. 1<<3 = 8. Shift Right (>>) moves the first operand to the right by the number of bits specified by the second operand, and the vacated position is 0. The right shift is equivalent to divide. Shift right one is equivalent to dividing by 2, the right shift two is equivalent to dividing by 4, and the right shift three bits is equivalent to dividing by 8. 16>>4 = 1.
7. Merge operator: If the left operand of this operator is not NULL, this operator returns the left operand, otherwise the right operand is returned.
int x = NULL;


Set y to the value of X if x are not null; otherwise
If x = null, set y to-1.
int y = x?? -1;
8.^ operator: For integer, ^ calculates the bitwise XOR of the operand. for bool operands, ^ calculates the logical "XOR" of the operand, which means that the result is true if and only if only one operand is true. True ^ false = True,false ^ false = False.
The 9.~ operator performs a bitwise complement operation on the operand, which is equivalent to reversing each bit. The bitwise complement operator is predefined for int, uint, long, and ulong types.

C # Operators

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.