Tag: inline if

Math.Max vs inline if – 有什么区别?

我今天正在研究一个项目,并发现自己在几个地方使用Math.Max并在其他地方使用内联if语句。 所以,我想知道是否有人知道哪个更“好”……或者更确切地说,真正的差异是什么。 例如,在下面, c1 = c2 : Random rand = new Random(); int a = rand.next(0,10000); int b = rand.next(0,10000); int c1 = Math.Max(a, b); int c2 = a>b ? a : b; 我是专门询问C#,但我想在不同的语言中答案可能会有所不同,但我不确定哪些有类似的概念。