VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/c-sharp-math-divrem-method/

⇱ C# | Math.DivRem() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C# | Math.DivRem() Method

Last Updated : 11 Jul, 2025

In C#, Math.DivRem() is a Math class method which divides two numbers and returns the remainder. By using Division operator, we do not get the remainder in a separate variable but using DivRem() method, we get both.

This method can be overloaded by passing different type and number of arguments to it.

  1. Math.DivRem(Int32, Int32, Int32)
  2. Math.DivRem(Int64, Int64, Int64)

Math.DivRem(Int32, Int32, Int32)

This method is used to calculate the quotient of two 32-bit signed integers and returns the remainder in an output parameter.

Syntax:

public static int DivRem(int dividend, int divisor, int result);

Parameter:

dividend: It is an Input Dividend number of type Int32. divisor: It is an Input Divisor number of type Int32. result: It is an output Remainder of type Int32.

Return Type:

This function returns the quotient of the specified numbers of type Int32.

Exception:

If the value of Divisor is zero then this method will give DivideByZeroException.

Example:


Output
1406474
6
-49999
-1

Math.DivRem(Int64, Int64, Int64)

This method is used to calculate the quotient of two 64-bit signed integers(long) and returns the remainder in an output parameter.

Syntax:

public static long DivRem(int dividend, int divisor, int result);

Parameter:

dividend: It is an Input Dividend number of type Int64. divisor: It is an Input Divisor number of type Int64. result: It is an output Remainder of type Int64.

Return Type:

This function returns the quotient of the specified numbers of type Int64.

Exception:

If the value of Divisor is zero then this method will give DivideByZeroException.

Example:


Output
4611686018427387
1779
-130050197929
-359476

References:

https://learn.microsoft.com/en-us/dotnet/api/system.math.divrem?view=netframework-4.7.2
Comment
Article Tags:

Explore