编译器无法识别为 true 的最简单 'true' 值
Simplest 'true' value that the compiler doesn't recognise as true
我有一点调试拦截说
if (true)
throw new Exception()
DoStuff();
但是编译器警告我 DoStuff() 是无法访问的代码。以下是:
if (1==1)
if (1 + 1 == 2)
以下'works'
int x = 1;
if (2 * x == 2)
throw...
什么表达式对人类来说显然是正确的,但对编译器来说却不是?我能做到的最好的是
bool False =>false;
if (False)
...而且它有美妙的 属性 要关闭它我所要做的就是将它更改为
bool False=>true /* :D) */
无需弄乱您的代码,您可以这样做:
[System.Diagnostics.Conditional("DEBUG")]
void stop() { throw new Exception(); }
Debug
中存在但Release
中不存在的方法,正常使用:
void MyMethod()
{
stop(); // If you're in Release, this invocation will be removed
DoStuff();
}
我一直在我的代码片段中这样做,我的方法遵循命名约定 DebugConditional_CopyPasteOfContainerName()
我有一点调试拦截说
if (true)
throw new Exception()
DoStuff();
但是编译器警告我 DoStuff() 是无法访问的代码。以下是:
if (1==1)
if (1 + 1 == 2)
以下'works'
int x = 1;
if (2 * x == 2)
throw...
什么表达式对人类来说显然是正确的,但对编译器来说却不是?我能做到的最好的是
bool False =>false;
if (False)
...而且它有美妙的 属性 要关闭它我所要做的就是将它更改为
bool False=>true /* :D) */
无需弄乱您的代码,您可以这样做:
[System.Diagnostics.Conditional("DEBUG")]
void stop() { throw new Exception(); }
Debug
中存在但Release
中不存在的方法,正常使用:
void MyMethod()
{
stop(); // If you're in Release, this invocation will be removed
DoStuff();
}
我一直在我的代码片段中这样做,我的方法遵循命名约定 DebugConditional_CopyPasteOfContainerName()