gpt4 book ai didi

c# - C# 是否在 if(false) block 内编译代码?

转载 作者:可可西里 更新时间:2023-11-01 08:11:06 24 4
gpt4 key购买 nike

我只是想知道这些代码块是否被编译成.dll

我不认为这个会被编译

#if SOMETHING_UNDEFINED
// some code - this is ignored by the compiler
#endif

现在这些呢?

1.

if(false) {
// some code - is this compiled?
}

2.

const bool F = false;
if(F) {
// some code - is this compiled?
}

3.

bool F = false;
if(F) {
// some code - is this compiled?
}

编辑:抱歉,我说的是 Visual Studio

最佳答案

只是测试它,Microsoft C# 4 编译器没有,看起来 Mono gmcs 编译器版本 2.4.0.0 也没有。不过,我不知道规范中有什么内容禁止它。

编辑:当我回答这个问题时,只有第一个版本存在。情况 2 等同于情况 1,但情况 3 不是。

关于c# - C# 是否在 if(false) block 内编译代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2779200/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com