C# Tutorial C# Advanced C# Resources
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

C# - Math DivRem() Method



The C# Math DivRem() method is used to calculate the quotient of two numbers and also returns the remainder in an output parameter. The method can be overloaded and it can take int and long arguments.

Syntax

public static int DivRem (int a, int b, out int result);
public static long DivRem (long a, long b, out long result);

Parameters

a Specify the dividend.
b Specify the divisor.
result Specify the name of the variable.

Return Value

Returns the quotient of specified numbers.

Example:

In the example below, DivRem() method is used to calculate the quotient of two numbers. The remainder is stored in the variable called remainder.

using System;

class MyProgram {
  static void Main(string[] args) {
    int quot = Math.DivRem(100, 30, out int remainder);
    Console.WriteLine(quot); 
    Console.WriteLine(remainder); 
  }
}

The output of the above code will be:

3
10

❮ C# Math Methods

5