The assignment operator in the C # tutorial [original]

Source: Internet
Author: User

Till now, we have been using the simple = value assignment operator. In fact, there are other value assignment operators, and they are all very useful. Except the = Operator, all other value assignment operators work in a similar way.

Like =, they all assign a value to the variable on the left Based on the operator and the right operand. The following table lists the operators and their descriptions.

 

Result of the example expression of the operator class

 

= Binary var1 = var2; var1 is assigned the value of var2

 

+ = Binary var1 + = var2; var1 is assigned the sum of var1 and var2

 

-= Binary var1-= var2; var1 is given the difference between var1 and var2

 

* = Binary var1 * = var2; var1 is given the product of var1 and var2

 

/= Binary var1/= var2; var1 is given the result of division between var1 and var2.

 

% = Binary var1 % = var2; var1 is given the remainder obtained by Division of var1 and var2.

 

We can see that these operators include var1 in the calculation process, the following code:

 

Var1 + = var2;

 

The result is the same as the following code.

 

Var1 = var1 + var2;

 

The + = operator can also be used as a string, the same as the + operator.

 

Using these operators, especially when using long variable names, makes the code easier to read.

 

This article is a new one. For more information, see the source and author!

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.