Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# check which integer is higher

I have two integers, int1 and int2. I want to check which one is the higher one. How can I do this the best? Is there an C#.NET function for this or do I have to write it myself?

Ofcource I can do something similar to this:

if (int1 < int2)
    return int1;
else
    return int2;

But I was wondering if there is a more elegant way for doing this?

yours, Bernhard

like image 707
Bernhard Avatar asked Nov 28 '22 15:11

Bernhard


1 Answers

Math.Max

Usage:

int highest = Math.Max(int1, int2);

It's overloaded for all numeric types.

like image 139
ChrisF Avatar answered Dec 04 '22 11:12

ChrisF