我簡直不能讓我的頭繞着這個簡單的問題。布爾沒有被設置爲真正的C#
我有我asigning到測試的輸出一個布爾值:
// these are passed in to the function and will vary
bool inReview = true;
char status = 'V';
bool test = (inReview && status != 'M') || !inReview;
計算結果爲:
bool test = (true && true) || !true;
這應該是真實的 - 但調試器顯示的「值測試「是錯誤的。
當我試試這個:
bool inReview = true;
char status = 'V';
bool test = false;
if ((inReivew && status != 'M') || !inReview)
{
test = true;
}
它落入如果和調試器顯示的「測試」的價值是真實的。
現在,這裏是別的東西很奇怪,如果我這樣做:
bool test = (inReview && status != 'M') || !inReview;
bool test2 = (inReview && status != 'M') || !inReview;
步進通過與調試程序 - 測試首先是假的,test2的成爲真正的瞬間,但後來當我檢查測試,現在是真的!?
另外,如果我嘗試:
bool test = (inReview && status != 'M') || !inReview;
if (test)
{
string s = "WTF?";
}
步進通過 - 測試首先是假的,那麼它確實步入如果和值現在是true!?
最後一個是非常可疑的。 'test'在該行被設置爲'_before_或_after_'後是否爲false? – David
bool test =(inReview && status!='M')|| !inReview;這返回true,不要通過Statement Console.Write(test.ToString())繼續進行調試器打印測試; – Adil
設置斷點** AFTER **'bool test'行! –