我有以下代碼示例,其中If語句的2個部分之間的唯一區別是小於/大於運算符。如何編寫2個語句,這些語句在VB.NET中僅由操作符類型區分
有沒有更好的方法來寫這個?幾乎可以做到定義一個Operator變量。
If myVar = true Then
Do While (X < Y)
'call Method A
'the values of X and Y will change within this loop
Loop
Else
Do While (X > Y)
'call Method A
'the values of X and Y will change within this loop
Loop
End If
感謝
除了源代碼的行數你可能是最快的。 iif和if()是非常緩慢的。 – dbasnett 2010-04-19 12:29:43
@dbasnett - 你是指If()運算符還是If()函數?如果前者,你能提供一個鏈接來詳細說明If()運算符的性能問題嗎? – 2010-04-19 16:50:42