2013-08-28 55 views
0

我有以下代碼:重構情況下,選擇進入if語句

Dim useFont As Font = e.Font 
    Dim myBrush As Brush = Brushes.Black 
    ' Determine the font to draw each item based on  
    ' the index of the item to draw. 
    If e.Index = 0 Or 7 Or 10 Or 13 Then 
     useFont = New Font(e.Font, FontStyle.Bold) 
    Else 
     useFont = DefaultFont 
    End If 

    ' Select e.Index 
    ' Case 0 
    'useFont = New Font(e.Font, FontStyle.Bold) 
    ' Case 7 
    'useFont = New Font(e.Font, FontStyle.Bold) 
    ' Case 10 
    'useFont = New Font(e.Font, FontStyle.Bold) 
    ' Case 13 
    'useFont = New Font(e.Font, FontStyle.Bold) 
    'End Select 

下注釋掉的代碼是我老了,工作代碼。我認爲我最好重寫它,使其更加緊湊和可讀,但是我無法弄清楚如何執行與case select相同的功能,因爲它只會導致所有列表項變爲粗體。我不知道我是不是誤解了OR運算符,OrElse也不工作。

任何人都可以給我一些正確的方向?謝謝。

+1

「緊湊型」和「讀取」通常是相互排斥的代碼狀態。 :P – Casey

回答

4
If e.Index = 0 Or e.Index= 7 Or e.index=10 Or e.index=13 Then 

但是你同樣可以做得

Case 0,7,10,13 
+0

謝謝,似乎我需要刷新我的語法多一點。 – SCGB