gpt4 book ai didi

c# - "else if()"与 C# 中的多个 "if()"

转载 作者:IT王子 更新时间:2023-10-29 04:45:15 26 4
gpt4 key购买 nike

这些实际上有何不同?

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

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

生成的 CIL 是否相同?

(问题 Use of “if/elseif/else” versus “if/else{if/else}” 存在,但尚未得到解答。)

最佳答案

如果 DoSomethingx 设置为 2,那么它们将不同。

关于c# - "else if()"与 C# 中的多个 "if()",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14349261/

26 4 0
文章推荐: c# - 什么时候在 C# 中使用@?
文章推荐: javascript - Vue.js : "TypeError: Cannot set property props of# which has only a getter"