.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.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn C# on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn C#
Learn Microsoft's popular C# programming language, used to make websites, mobile apps, video games, VR, and more.Beginner Friendly23 hours