C # arithmetic operators and arithmetic expressions

Source: Internet
Author: User
Tags arithmetic arithmetic operators

There are five of arithmetic operators available in C #:

+ addition operator

-Subtraction operator

* Multiplication operator

/Division Operator

% remainder operator

In the operation of an expression, expressions are always evaluated in the order in which they are written, as in the following example:

Program Listing 7-1:

Using System;

Class Test
{
  static void F (int x,int y,int z) {
     Console.WriteLine ("X={0},y={1},z={2}", x,y,z);
 }
     public static void Main () {
     int i=0;
     F (i++,i++,i++);
 }
Output Result:

x=0,y=1,z=2

7.2.1 addition operation

7.2.2 Subtraction Operation

7.2.3 multiplication operation

7.2.4 Division Operations

7.2.5 calculation

The "/" operator is used to find the quotient of division, and the "%y" operator is used to find the remainder of the division. The modulo operation in C # applies both to the integer type and to the floating-point type and the decimal type. For example, the result of 5%3 for 2,5%1.5 is 0.5.

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.