Fundamentals of C # Programming--Operators and expressions

Source: Internet
Author: User
Tags bitwise bitwise operators

An operator is a series of symbols that perform operations, which mainly include arithmetic operators, assignment operators, relational operators, logical operators, conditional operations, bitwise manipulation operators, and string operators.

An expression is a combination of operators and operands, such as a*b+1-c. Expressions mainly include arithmetic expressions, assignment expressions, conditional expressions, and Boolean expressions.

Arithmetic operators and expressions

C # provides five operators: the "+" addition operator, the "-" subtraction operator, the "*" multiplication operator, the "/" division operator, and the "%" modulo operator. The precedence of arithmetic operators is calculated in the order in which they are multiplication and then added and reduced.

Assignment operators and expressions

Assigning a value is giving a new value to a variable. The assignment operators in C # are: =, + =,-=, *,/=,%=, &=, |=, >>=, <<=, ^=. In C #, variables are allowed to be continuously assigned, such as A=b=c. The binding of the assignment operator is from right to left combined, so a=b=c is equivalent to A= (b=c).

relational operators and expressions

A relational operator is actually a "judgment" symbol with the result of true (true) or False (false), so the relational expression always returns a Boolean value.

logical operators and expressions

C # consists of three logical operators: "With (&&)", "or (| | ) "," Non-(! )”。 Which, "!" The operator is a single-mesh operator, meaning it has only one operand. Their operands are expressions of a Boolean or Boolean value, and the operation result is a Boolean value of "true" or "false".

Bitwise operators

The bitwise operators can be divided into shift operators and logical bits operators. Any information in the computer is stored in binary form, and the bitwise operator is the operator that operates on the data in binary order. The operators in C # include ">>", "<<", "^", "&", "|", "~".

Self-increment and decrement operators

The self-increment, decrement operator is a single-mesh operator, and the binding is "right-to-left", and their effect is to increase the value of the variable by 1 or minus 1. Such as:

--i,++i (before using I, let the value of I minus (plus) 1)

I--,i++ (after using I, first reduce the value of I (plus) 1)

Other operators

Conditional operators

The conditional operator can assign a value to a condition-based variable, which requires three operands, called a three-mesh uniform character. Syntax: variable name = (condition)? value 1: Value 2. The binding of the conditional operator is "from right to left", which is executed in the order that the conditional expression evaluates to a if the condition is true, otherwise the value is B.

Comma operator

The general form of a comma expression is: expression 1, Expression 2

The order of execution of the comma expression is: first solve expression 1, then solve Expression 2. The value of the entire comma expression is the value of expression 2. For example, the expression "1+2,3+4", the value of the comma expression is 7.

Fundamentals of C # Programming--Operators and expressions

Related Article

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: 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.