C # mathematical operators

Source: Internet
Author: User

Operators are roughly divided into the following three types:

  • Unary operator, processing an operator
  • Binary operator, processing two operands
  • Three-element operator, processing three operands

Most operators are binary operators. There are only a few unary operators and a ternary operator, that is, a conditional operator (a conditional operator is a logical operator ). The following describes mathematical operators, including unary and binary operators.

 

I. mathematical operators

There are five simple mathematical operators, two of which have two forms: two yuan and one yuan. The following table lists these operators and uses a short example to describe their usage and their results when using a simple numeric type.

Operator Class Example expression Result
+ Binary Var1 = var2 + var3; The value of var1 is the sum of var2 and var3.
- Binary Var1 = var2-var3; The value of var1 is the difference between var2 and var3.
* Binary Var1 = var2 * var3; The value of var1 is the product of var2 and var3.
/ Binary Var1 = var2/var3; Var1 is the value obtained by dividing var2 by var3.
% Binary Var1 = var2 % var3; Var1 is the remainder of var2 divided by var3.
+ RMB 1 Var1 = + var2; The value of var1 is equal to the value of var2.
- RMB 1 Var1 =-var2; The value of var1 is equal to the value of var2 multiplied by-1.

The PS: + (mona1) operator is a bit odd because it has no effect on the result. It does not convert the value to positive: If var2 is-1, + var2 is still-1. However, this is a universally recognized operator, so it is also included.

 

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.