Skip to main content
The / operator is a binary arithmetic operator that computes the quotient of its left-hand operand (the dividend) divided by its right-hand operand (the divisor). The execution behavior, return type, and exception handling of the operation are strictly determined by the numeric types of the operands evaluated at compile time.

Type Resolution and Execution Behavior

The C# compiler applies implicit numeric promotion to the operands before evaluating the division. Depending on the resolved types, the operator’s behavior falls into three distinct categories:

1. Integer Division

When both operands are of integral types (int, uint, long, ulong), the operator performs integer division.
  • Result: The fractional part of the quotient is discarded (truncated towards zero).
  • Exceptions:
    • Throws a System.DivideByZeroException if the right-hand operand evaluates to 0 at runtime.
    • Throws a System.OverflowException if dividing int.MinValue or long.MinValue by -1. This occurs regardless of the checked or unchecked context because the mathematically positive result exceeds the maximum representable value of the signed 32-bit or 64-bit integer type.

2. Floating-Point Division

When at least one operand is a floating-point type (float or double), the operator performs floating-point division in compliance with the IEEE 754 standard.
  • Result: A floating-point quotient retaining fractional precision.
  • Exceptions: Never throws an exception. Division by zero yields specific constant values:
    • PositiveInfinity: Non-zero positive dividend divided by 0.0.
    • NegativeInfinity: Non-zero negative dividend divided by 0.0.
    • NaN (Not a Number): 0.0 divided by 0.0.

3. Decimal Division

When at least one operand is of type decimal (and the other is not a floating-point type), the operator performs high-precision base-10 division.
  • Result: A decimal quotient. The scale of the result is determined by the scales of the operands and the precision required to represent the quotient.
  • Exceptions:
    • Throws a System.DivideByZeroException if the right-hand operand evaluates to 0m at runtime.
    • Throws a System.OverflowException if the resulting quotient is too large to be represented within the decimal type’s limits.

Operator Overloading

The / operator can be overloaded for user-defined types (classes and structs) using the operator keyword. The method must be declared as public static.

Compound Assignment

The / operator serves as the foundation for the /= compound assignment operator. This operator divides the left-hand variable by the right-hand operand and assigns the resulting quotient back to the left-hand variable. When a custom type overloads the / operator, the /= operator is implicitly overloaded.
Tired of Poor C# Skills? Fix That With Deep Grasping!Learn More