If statement appears to be evaluating even when condition evaluates to false

前端 未结 5 2007
梦如初夏
梦如初夏 2020-12-28 19:47

Late At Work last night, we were trying to figure out why something was failing. A validation check was failing when it shouldn\'t have been.

We ended up adding a pr

5条回答
  •  甜味超标
    2020-12-28 20:41

    I had something similar a while ago. In my case it had to do with the fact that i was comparing 2 integer values where one value was actually a reference to a boxed integer and the other was a real primitive value.

    The thing is that if you print out the value of the boxed integer and the primitive, they look the same, but comparing them is another thing. You'll get a reference comparison in stead of a value comparison.

    The answer is easy:

    long ticks = lastModified.Ticks;
    long num2 = ticks - (ticks % 10000L);
    if ((ticks != num2) && (lastModified != DateTime.MaxValue))
    { do your thing here! }
    

提交回复
热议问题