C# .BigMul()

ksuraev's avatar
Published Nov 19, 2025
Contribute to Docs

The Math.BigMul() method multiplies two integer values and returns the full extended result to avoid overflow. It ensures that the product fits within a larger data type when the operands are 32-bit or 64-bit integers.

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn Microsoft's popular C# programming language, used to make websites, mobile apps, video games, VR, and more.
    • Beginner Friendly.
      15 hours

Syntax

Math.BigMul(x, y);

Parameters:

  • x, y: The integers to be multiplied. These can be of type int, uint, long, or ulong.

Return value:

Returns the full product of x and y as a single 64-bit or 128-bit integer, depending on the input type:

  • If x and y are of type int or uint, the return type is long and ulong, respectively.
  • If x and y are of type long or ulong, the return type is Int128 and UInt128, respectively.

Note: The Int128 and UInt128 types were introduced in .NET 7. In earlier versions, Math.BigMul(long, long, out long high) can be used to obtain the high and low 64-bit parts of the product.

Example: Basic Usage

In this example, the full product of two int values is calculated without overflow:

using System;
public class Example {
public static void Main() {
// Integer values (32-bit)
int intX = 100000;
int intY = 500000;
// Compute the product safely
long intResult = Math.BigMul(intX, intY);
Console.WriteLine($"Math.BigMul({intX}, {intY}) = {intResult}");
}
}

This example outputs the following:

Math.BigMul(100000, 500000) = 50000000000

Codebyte Example

The following example demonstrates the use of Math.BigMul() to calculate the product of two integers that would normally cause an overflow with standard multiplication:

Code
Output
Loading...

All contributors

Contribute to Docs

Learn C# on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn Microsoft's popular C# programming language, used to make websites, mobile apps, video games, VR, and more.
    • Beginner Friendly.
      15 hours