"else if()";与C#中的多个"if()"相比 [英] "else if()" versus multiple "if()"s in C#
本文介绍了"else if()";与C#中的多个"if()"相比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这些实际上有何不同?
// Approach one
if (x == 1)
DoSomething();
else if (x == 2)
DoSomethingElse();
// Approach two
if (x == 1)
DoSomething();
if (x == 2)
DoSomethingElse();
生成的CIL是否相同?
Is the resulting CIL the same?
(问题 使用存在"if/elseif/else"与"if/else {if/else}" ,但尚未得到答复.)
推荐答案
如果 DoSomething
将 x
设置为2,则它们将有所不同.
If DoSomething
sets x
to 2, then they will differ.
这篇关于"else if()";与C#中的多个"if()"相比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文