C#否则,如果()与多个if() [英] c# else if () versus multiple if ()

查看:179
本文介绍了C#否则,如果()与多个if()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有看到这个重复的问题,但我相信有人有更好的搜索能力比我会找到一个。但是,在没有,因为我确实知道的:

I don't see a duplicate question to this, but I am sure someone with better search skills than I have will find one. But in the absence, and since I really do what to know:

这问题(的使用如果/ ELSEIF /其他对的if / else {的if / else})存在,但仍有待回答说。

This question ("use of "if/elseif/else" versus "if/else{if/else}") exists but is yet to be answered.

如何将这些实际上有什么不同?

How do these practically differ?

// approach one
if (x == 1)
    DoSomething();
else if (x == 2)
    DoSomethingElse();

// approach two
if (x == 1)
    DoSomething();
if (x == 2)
    DoSomethingElse();

时所产生的IL相同?

推荐答案

如果的DoSomething X 2,那么他们会有所不同。

If DoSomething sets x to 2, then they will differ.

这篇关于C#否则,如果()与多个if()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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