.Max()
Published Feb 15, 2023Updated Apr 29, 2023
Contribute to Docs
The Math.Max()
method returns the greater of two specified numbers.
Syntax
Math.Max(num1, num2)
Math.Max()
returns the greater value from num1
and num2
.
Example
The following example compares two integers i1
and i2
and writes the greater integer to the console.
using System;public class Example {public static void Main (string[] args) {int i1 = -234, i2 = 345;Console.WriteLine("Math.Max (int) = " + Math.Max(i1,i2));}}
This example results in the following output:
Math.Max (int) = 345
Codebyte Example
The following example is runnable and uses the Math.Max()
method to return the greater number from the given two integer
type numbers, number1
and number2
:
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