Arithmetic Operators - CSharp Language Basics

CSharp examples for Language Basics:Operator

Introduction

The arithmetic operators (+, -, *, /, %) are defined for all numeric types except the 8-and 16-bit integral types:

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

Increment and Decrement Operators

The increment and decrement operators (++, --) increment and decrement numeric types by 1.

The operator can either follow or precede the variable, depending on whether you want its value before or after the increment/decrement.

For example:

Demo Code

using System;/*from   w  ww . j  a  v  a2 s.  c  o  m*/
class Test
{
   static void Main(){
      int x = 0, y = 0;
      Console.WriteLine (x++);   // Outputs 0; x is now 1
      Console.WriteLine (++y);   // Outputs 1; y is now 1
   }
}

Result


Related Tutorials