I found the following code in my team's project:
Public Shared Function isRemoteDisconnectMessage(ByRef m As Message)
isRemoteDisconnectMessage = False
Select Case (m.Msg)
Case WM_WTSSESSION_CHANGE
Select Case (m.WParam.ToInt32)
Case WTS_REMOTE_DISCONNECT
isRemoteDisconnectMessage = True
End Select
End Select
End Function
Never mind that the function doesn't have a return type (I can easily add 'As Boolean'); what I'm wondering is, could there be any reason to prefer the above over the following (to me, much more readable) code?
Public Shared Function isRemoteDisconnectMessage(ByRef m As Message) As Boolean
Return m.Msg = WM_WTSSESSION_CHANGE AndAlso _
m.WParam.ToInt32() = WTS_REMOTE_DISCONNECT
End Function
To put the question in general terms: Does it make sense to use a switch
(or, in this case, Select Case
) block--and/or nested blocks--to test a single condition? Is this possibly faster than a straightforward if
?