Facebook Page Twitter Page LinkedIn Page
× C# Tutorial C# Advanced C# Resources


The C# Min() method is used to return minimum number between the two arguments. The method can be overloaded and it can take long, decimal, double, float, int, short, byte, ulong, uint, ushort, and sbyte arguments. If either of the arguments is NaN, the method returns NaN.

Syntax

public static ulong Min (ulong arg1, ulong arg2);
public static uint Min (uint arg1, uint arg2);
public static ushort Min (ushort arg1, ushort arg2);
public static float Min (float arg1, float arg2);
public static sbyte Min (sbyte arg1, sbyte arg2);
public static byte Min (byte arg1, byte arg2);
public static int Min (int arg1, int arg2);
public static short Min (short arg1, short arg2);
public static double Min (double arg1, double arg2);
public static decimal Min (decimal arg1, decimal arg2);
public static long Min (long arg1, long arg2);

Parameters

arg1 Specify value to compare.
arg2 Specify value to compare.

Return Value

Returns the numerically minimum value.

Example:

In the below example, Min() method is used to find out the minimum value between the two arguments.

using System;

class MyProgram {
  static void Main(string[] args) {
   int x = 50, y = 100;
   float p = 5.5f, q = 10.5f;

   Console.WriteLine("Math.Min(" + x + "," + y + ") returns: " + Math.Min(x, y));
   Console.WriteLine("Math.Min(" + p + "," + q + ") returns: " + Math.Min(p, q));
  }
}

The output of the above code will be:

Math.Min(50,100) returns: 50
Math.Min(5.5,10.5) returns: 5.5

❮ C# Math Methods