MathF.Min() Method in C# with Examples


The MathF.Min() method in C# returns the smallest of the two specified numbers.

Syntax

Following is the syntax −

public static float Min (float val1, float val2);

Above, val1 is the first number, whereas val2 is the second number. Both of these numbers are compared.

Example

Let us now see an example to implement the MathF.Min() method −

using System;
public class Demo {
   public static void Main(){
      float val1 = 6.89f;
      float val2 = 4.45f;
      Console.WriteLine("Minimum Value = "+MathF.Min(val1, val2));
   }
}

Output

This will produce the following output −

Minimum Value = 4.45

Example

Let us now see another example to implement the MathF.Min() method −

using System;
public class Demo {
   public static void Main(){
      float val1 = 1.00f;
      float val2 = 0.11f;
      Console.WriteLine("Minimum Value = "+MathF.Min(val1, val2));
   }
}

Output

This will produce the following output −

Minimum Value = 0.11

Updated on: 14-Nov-2019

42 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements