0Pricing
C# Academy · Lesson

Arithmetic and Assignment Operators

Use +, -, *, /, % and compound assignment forms.

Arithmetic Operators

C# gives you the classic math operators: + add, - subtract, * multiply, / divide, and % remainder (modulo).

They work on numeric types like int, long, double, and decimal.

using System;

class Program {
    static void Main() {
        int a = 10, b = 3;
        Console.WriteLine(a + b);
        Console.WriteLine(a - b);
        Console.WriteLine(a * b);
    }
}

Integer Division

When both operands are integers, / performs integer division and truncates the fractional part.

10 / 3 is 3, not 3.33.

using System;

class Program {
    static void Main() {
        int result = 10 / 3;
        Console.WriteLine(result);
        Console.WriteLine(7 / 2);
    }
}

All lessons in this course

  1. Arithmetic and Assignment Operators
  2. Comparison and Logical Operators
  3. Bitwise and Shift Operators
  4. Operator Precedence and Associativity
← Back to C# Academy