MathF.Max() Method in C# with Examples


The MathF.Max() method in C# returns the larger of the two specified numbers.

Syntax

Following is the syntax −

public static float Max (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.Max() method −

using System;
public class Demo {
   public static void Main(){
      float val1 = 11.89f;
      float val2 = 55.67f;
      Console.WriteLine("Maximum Value = "+MathF.Max(val1, val2));
   }
}

Output

This will produce the following output −

Maximum Value = 55.67

Example

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

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

Output

This will produce the following output −

Maximum Value = 1

Updated on: 14-Nov-2019

19 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements