CSharp - Operator Arithmetic Operators

Introduction

The arithmetic operators in C# is listed as follows.

Operator Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
% Remainder after division

Increment and Decrement Operators

The increment and decrement operators ++, -- respectively.

They increment and decrement numeric types by 1.

The operator can either follow or precede the variable.

Adding increment and decrement operators follow or precede determines whether you want its value before or after the increment/decrement.

For example:

Demo

using System;
class MainClass//from  w w  w.j  ava2s. c o m
{
   public static void Main(string[] args)
   {

     int x = 0, y = 0;
     Console.WriteLine (x);  
     Console.WriteLine (y);  

     Console.WriteLine (x++);   // Outputs 0; x is now 1
     Console.WriteLine (++y);   // Outputs 1; y is now 1

     Console.WriteLine (x);  
     Console.WriteLine (y);  

   }
}

Result

Exercise