المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Boolean value changes without being modified, don't know why.



C# Programming
01-12-2010, 07:11 PM
Hey,

I'm working on a C# project where I'm using a boolean flag to determine if I need to recompute a value, but when I get to evaluating the boolean flag (in an if statement), if it's false, it will just flip the value of the flag to true, and enter the if block anyway. For clarification:


if (currAreaValid)
{
return area;
}



that's it. That's all the code. currAreaValid is false when it reaches the if statement, then just turns to true, and my method returns area. Now, it gets a little nuttier. If I hardcode "false" in the if statement, instead of currAreaValid, the value of currAreaValid still flips after the if block. I don't know why. I've tried cleaning and rebuilding the solution, but that didn't help. Has anyone seen a problem like this before? The only place I set the value of currAreaValid to true is in the same method that this if block is in, but at the very end of the method, which is 2 lines after the if block.

I have no idea what's going on. Can anyone help?