Math.Max VS直列如果 - 有什么区别? [英] Math.Max vs inline if - what are the differences?

查看:162
本文介绍了Math.Max VS直列如果 - 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是在一个项目工作今天,并发现自己在几个地方和内联如果在其他地方语句中使用Math.Max。所以,我想知道是否有人知道这是更好......或者说,真正的区别是什么。

I was working on a project today, and found myself using Math.Max in several places and inline if statements in other places. So, I was wondering if anybody knew which is "better"... or rather, what the real differences are.

例如,在下面, 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#,但我想答案可能是在不同的语言不同,但我不知道哪些有类似的概念。

I'm asking specifically about C#, but I suppose the answer could be different in different languages, though I'm not sure which ones have similar concepts.

推荐答案

一个主要的区别我会注意到马上将是可读性缘故,因为据我所知,实施/性能的缘故,他们会的的等价物。

One of the major differences I would notice right away would be for readability sake, as far as I know for implementation/performance sake, they would be nearly equivalent.

Math.Max (A,b)很简单易懂,不管以前的编码知识

Math.Max(a,b) is very simple to understand, regardless of previous coding knowledge.

A> b?答:; B 将要求用户有三元运算符的一些知识,至少

a>b ? a : b would require the user to have some knowledge of the ternary operator, at least.

如果有疑问 - 去为便于阅读

这篇关于Math.Max VS直列如果 - 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆