Wednesday, 28 August 2013

Refactoring case select into if statement

Refactoring case select into if statement

I have the following code:
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
The commented out code below is my old, working code. I thought I better
rewrite it to make it more compact and readable, however I cannot work out
how to perform the same function as the case select, as it just results in
all my list items becoming bold. I don't know if I'm just misunderstanding
the OR operator, and OrElse does not work either.
Can anybody give me some pointers in the right direction? Thanks.

No comments:

Post a Comment