![]() |
VOOZH | about |
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.
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:
1406474 6 -49999 -1
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:
4611686018427387 1779 -130050197929 -359476
References:
https://learn.microsoft.com/en-us/dotnet/api/system.math.divrem?view=netframework-4.7.2