VB行爲:
你說,這是用VB編寫的,所以,我認爲原來的代碼如下所示:
If boolVariable = 13 Then // Remeber : it was VB..
// Code block if True
// ...
Else
// Code block if False
// ...
End If
現在讓我們來看看代碼將如何表現。 ..
// Remeber : it was VB..
If boolVariable = 13 Then
/* The boolVariable is a Boolean
The "13" is an Integer
First step is performing a Widening conversion Boolean -> Integer
boolVariable is converted to 0 if False, or 1 if True.
So, depending on the value of boolVariable, the statement is
either : */
If 0 = 13 Then // which is False
// either :
If 1 = 13 Then // which is also False
// That means that writing If boolVarialbe = 13 is the same as writing :
If False Then
// Block of code THAT WILL NEVER BE EXECUTED
Else
// Block of code that will ALWAYS be executed
End If
所以恕我直言,這是沒有意義的寫作If (boolVariable == 13)
(羯羊它的VB或C#)
當我正在測試特定的,在最終代碼中無關時,我正在做這些奇怪的事情。也許前程序員做了類似的事情,並且沒有刪除那部分代碼。不知道代碼的作用以及它對整體範圍的影響,我不能說它是否是應該修復的應用程序的關鍵部分,或者是垃圾。
無論如何,像這樣If (boolVar == numVar)
語句是編程(恕我直言)今天方式一不走前者程序員未能激活這將阻止他寫它Option Strict
。
當Visual Basic將數字數據類型值轉換爲布爾值時,0變爲False,其他所有值都變爲True。 – user1274820 2014-10-17 21:00:38
爲什麼13?爲什麼不是10?我會試着理解if語句背後的邏輯並重寫它,忽略愚蠢的數字。 – SimpleVar 2014-10-17 21:00:40
boolVariable是布爾值嗎?或者它是一個int,他命名爲boolVariable,因爲它返回一個布爾值。 – deathismyfriend 2014-10-17 21:03:36