0Pricing
C# Academy · Lesson

Arithmetic and Precedence

Operators and order of evaluation.

Arithmetic Operators

C# provides the familiar arithmetic operators:

  • + addition
  • - subtraction
  • * multiplication
  • / division
  • % remainder (modulo)

They work on every numeric type.

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 discards the fractional part.

So 7 / 2 is 3, not 3.5. This is a common source of beginner bugs.

int result = 7 / 2;
Console.WriteLine(result);

All lessons in this course

  1. Numeric Types
  2. Arithmetic and Precedence
  3. The Math Class
  4. Converting Between Numbers
← Back to C# Academy