MathF.Max() Method in C# with Examples
In C#, Max(Single, Single) is a MathF class method which is used to returns the larger of the two specified numbers.
Syntax: public static float Max (float x, float y);
Here, x and y are the two floating point numbers which are compared.Return Type: This method returns the maximum of the two numbers which specified into the parameter list and return type depends on the type of arguments passed.
Example:
// C# program to demonstrate the // MathF.Max(Single, Single) method using System; class GFG { // Main Method static void Main() { // taking different float values float f1 = 34.56f, f2 = 37.3412f; float f3 = -675.2f, f4 = -56.47f; // displaying result Console.WriteLine(MathF.Max(f1, f2)); Console.WriteLine(MathF.Max(f3, f4)); } } |
Output:
37.3412 -56.47