在C#中if(a == 5)或if(5 == a)之间有什么区别吗? [英] Is there any difference between if(a==5) or if(5==a) in C#?

查看:145
本文介绍了在C#中if(a == 5)或if(5 == a)之间有什么区别吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,


如果(a == 5)或if(5 == a)

if (a==5) or if (5==a)

在C#中,哪个更好?

in C#, Which one is better?

推荐答案

没有区别-假设 a是整数。

There's no difference - assuming that "a" is an integer.

我知道有些人喜欢 if(5 == a),因为在c& c ++如果您错误地编写了 if(5 = a),则您将得到编译器错误,而 if(a = 5)将导致错误。

I know some people prefer if (5==a) because in c & c++ if you wrote if (5=a) by mistake you'd get a compiler error while if (a=5) would result in a bug.

在后一种情况下,C#会引发编译器错误,因此这不是问题。

C# raises a compiler error in the latter case, so it's not an issue.

这篇关于在C#中if(a == 5)或if(5 == a)之间有什么区别吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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