C# Math - Min() Method
The C# Min() method returns 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 example below, Min() method is used to find out the minimum value between the two arguments.
using System; class MyProgram { static void Main(string[] args) { Console.WriteLine("Math.Min(50, 100) returns: " + Math.Min(50, 100)); Console.WriteLine("Math.Min(5.5f, 10.5f) returns: " + Math.Min(5.5f, 10.5f)); Console.WriteLine("Math.Min(5, 10.5f) returns: " + Math.Min(5, 10.5f)); Console.WriteLine("Math.Min(10, Double.NaN) returns: " + Math.Min(10, Double.NaN)); Console.WriteLine("Math.Min(10, Double.NegativeInfinity) returns: " + Math.Min(10, Double.NegativeInfinity)); Console.WriteLine("Math.Min(10, Double.PositiveInfinity) returns: " + Math.Min(10, Double.PositiveInfinity)); } }
The output of the above code will be:
Math.Min(50, 100) returns: 50 Math.Min(5.5f, 10.5f) returns: 5.5 Math.Min(5, 10.5f) returns: 5 Math.Min(10, Double.NaN) returns: NaN Math.Min(10, Double.NegativeInfinity) returns: -Infinity Math.Min(10, Double.PositiveInfinity) returns: 10
❮ C# Math Methods