> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# C# Division

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.

```csharp theme={"dark"}
var quotient = dividend / divisor;
```

## 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.

```csharp theme={"dark"}
int a = 13 / 5;  // Evaluates to 2
int b = -13 / 5; // Evaluates to -2

int zero = 0;
int c = 1 / zero; // Throws DivideByZeroException at runtime

int minusOne = -1;
int d = int.MinValue / minusOne; // Throws OverflowException at runtime
```

### 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`.

```csharp theme={"dark"}
double x = 13.0 / 5;   // Evaluates to 2.6
double y = 1.0 / 0.0;  // Evaluates to double.PositiveInfinity
double z = 0.0 / 0.0;  // Evaluates to double.NaN
```

### 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.

```csharp theme={"dark"}
decimal d1 = 13m / 5m; // Evaluates to 2.6m

decimal zero = 0m;
decimal d2 = 1m / zero; // Throws DivideByZeroException at runtime

decimal fractional = 0.1m;
decimal d3 = decimal.MaxValue / fractional; // Throws OverflowException at runtime
```

## 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`.

```csharp theme={"dark"}
public readonly struct Vector2
{
    public double X { get; }
    public double Y { get; }

    public Vector2(double x, double y)
    {
        X = x;
        Y = y;
    }

    public static Vector2 operator /(Vector2 vector, double scalar)
    {
        return new Vector2(vector.X / scalar, vector.Y / scalar);
    }
}
```

## 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.

```csharp theme={"dark"}
int value = 10;
value /= 2; // Semantically equivalent to: value = value / 2;
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor C# Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
