.Min()

Published Mar 2, 2023
Contribute to Docs

The Math.Min() method returns the lesser of two specified numbers.

Syntax

Math.Min(num1, num2)

Math.Min() returns the lesser value from num1 and num2.

Example

The following example compares two integers i1 and i2 and writes the lesser integer to the console.

using System;
public class Example {
public static void Main (string[] args) {
int i1 = -134, i2 = 268;
Console.WriteLine("Math.Min (int) = " + Math.Min(i1,i2));
}
}

This example results in the following output:

Math.Min (int) = -134

Codebyte Example

Try changing the values of xint1 and xint2 to see the results.

us
Visit us
code
Hide code
Code
Output
Hide output
Hide output
Loading...

All contributors

Looking to contribute?

Learn C# on Codecademy