> ## 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# Multiplication Assignment

The `*=` operator is the compound multiplication assignment operator. It multiplies the current value of the left-hand operand by the value of the right-hand operand and assigns the resulting product back to the left-hand operand.

## Syntax and Evaluation

```csharp theme={"dark"}
x *= y;
```

This expression is semantically equivalent to:

```csharp theme={"dark"}
x = x * y;
```

However, there is a strict evaluation difference: in the `*=` operation, the left-hand operand `x` is evaluated exactly once. If `x` is an expression with side effects, such as an array access where the index is determined by a method call, the method is invoked only once.

```csharp theme={"dark"}
int[] arr = { 2, 4, 6 };

static int GetIndex() => 1;

// GetIndex() is called exactly once, not twice.
arr[GetIndex()] *= 5; 
```

## Type Promotion and Implicit Casting

A critical mechanical feature of the `*=` operator is its handling of numeric type promotion. In C#, arithmetic operations on types smaller than 32 bits (`byte`, `sbyte`, `short`, `ushort`, `char`) automatically promote the operands to `int`.

Using the standard assignment (`x = x * y`) requires an explicit cast to narrow the `int` result back to the original type. The `*=` operator handles this underlying cast automatically.

```csharp theme={"dark"}
byte a = 10;
byte b = 2;

// Compiles successfully. The compiler evaluates this as: a = (byte)(a * b);
a *= b;

// Compilation error: Cannot implicitly convert type 'int' to 'byte'.
// a = a * b; 
```

## Operator Overloading

The `*=` operator cannot be explicitly overloaded in C#. Instead, it is implicitly evaluated using the binary multiplication operator (`*`). If a custom `class` or `struct` overloads the `*` operator, the `*=` operator automatically becomes available and utilizes that custom implementation.

```csharp theme={"dark"}
Matrix m = new Matrix(5);
m *= 3; // Valid. Evaluates using the overloaded '*' operator.

public readonly struct Matrix
{
    public readonly int Value;
    public Matrix(int value) => Value = value;

    // Overloading '*' implicitly provides '*=' functionality
    public static Matrix operator *(Matrix left, int right) 
    {
        return new Matrix(left.Value * right);
    }
}
```

## Thread Safety and Atomicity

The `*=` operator is not an atomic operation. It executes as a multi-step read-modify-write sequence:

1. Read the value of the left operand.
2. Multiply it by the right operand.
3. Write the result back to the memory location of the left operand.

Because it is not atomic, applying `*=` to a shared variable across multiple threads without synchronization (such as a `lock` statement) will result in race conditions. Unlike addition or increment operations, the `System.Threading.Interlocked` class does not provide a built-in method for atomic multiplication.

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