在if语句布尔错误的评估 [英] Bool wrong evaluated in If statement

查看:141
本文介绍了在if语句布尔错误的评估的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是出于好奇

我有我的code这个问题。

I have this problem on my code.

电子被评为,(我知道,越来越虚假通过查看在数据库中的数据),但如果语句不关心这一点,假设这是真的,并试图抛出异常。

e is evaluated as false, (and I know that is getting false by seeing the data in the db) but the if statement doesn't care that, and assumes that is true, and is trying to throwing the exception.

任何想法,为什么?

编辑:

  • 没有;在线路16的端部

  • There is no ; at the end of line 16.

是正确的,我检查了数据库中, 纠正越来越,这是预期的

The value false is correct, I have checked the database and is correct that is getting false, that was the expected

推荐答案

我看到了一个非常类似的问题,以便最近,但我不能找到它。虽然我还是考虑,这里是我记得它,如果它可以帮助你放心:

I saw a very similar question on SO recently but I cannot find it. While I'm off looking, here is what I remember from it, in case it helps ease your mind:

症状为:

  • 通过code步进通过调试器停在不该执行的行
  • 的code线是的不实际执行的,当一个调试器外运行
  • 添加花括号围绕code中的违规行解决问题。
  • Stepping through code via the debugger was stopping on a line that should not be executed
  • The line of code is not actually executed when run outside of a debugger
  • Adding curly braces around the offending line of code fixes the problem.

究其原因,是因为有多余的运算codeS是在调试功能的版本发射,支持单步调试。对于这样的版本发出的实际IL code包括什么都不做,除了存在额外的无操作IL指令,并通过code迈向之前中断执行时使用和/或真正的操作后,已经运行。

The reason has to do with the extra op codes that are emitted in Debug-enabled releases, to support step-through debugging. The actual IL code emitted for such releases includes extra "no-op" IL commands that do nothing except exist, and are used when stepping through code to break execution just before and/or after the "real" operations have run.

在这种情况下,IDE才刚刚感到困惑的code这行是当前一家立足于IL code它试图逐步执行。额外的运算code是存在的,因为它应该是,但调试器IDE错误地用了code中的previous行关联起来。黄色的亮点是在错误的地方。

In this case, the IDE is just getting confused about which line of code is the "current" one based on the IL code it's trying to step through. The extra op code is there, as it should be, but the debugger IDE is incorrectly associating it with the previous line of code. The yellow highlight is in the wrong place.

我不记得确切的条件做到这一点(的答案,原来的问题实际上是挖成IL来解释它,希望有人能找到这个问题!)。添加括号会导致编译器发出无操作OP codeS专门重新present大括号,这就是为什么这个问题就消失了。

I don't remember the exact conditions that make this happen (the answer to the original question actually dug into the IL to explain it, hopefully someone else can find that question!). Adding the braces causes the compiler to emit no-op op codes specifically to represent the braces, which is why the problem vanishes.

这篇关于在if语句布尔错误的评估的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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