C#检查哪个整数更高

Ber*_*ard 5 c# integer compare

我有两个整数,int1int2.我想检查哪一个更高一个.我怎么能做到最好?是否有C#.NET函数或我是否必须自己编写?

Ofcource我可以做类似的事情:

if (int1 < int2)
    return int1;
else
    return int2;
Run Code Online (Sandbox Code Playgroud)

但我想知道是否有更优雅的方式来做这件事?

你的,伯恩哈德

Chr*_*isF 21

Math.Max

用法:

int highest = Math.Max(int1, int2);
Run Code Online (Sandbox Code Playgroud)

它为所有数字类型重载.