VB.NET Switch Statement GoTo Case

前端 未结 9 995
你的背包
你的背包 2020-12-10 23:42

I am writing some code in VB.NET that uses a switch statement but in one of the cases it needs to jump to another block. In C# it would look like this:

switc         


        
相关标签:
9条回答
  • 2020-12-11 00:28

    Why don't you just refactor the default case as a method and call it from both places? This should be more readable and will allow you to change the code later in a more efficient manner.

    0 讨论(0)
  • 2020-12-11 00:31
    Select Case parameter 
        Case "userID"
            ' does something here.
        Case "packageID"
            ' does something here.
        Case "mvrType" 
            If otherFactor Then 
                ' does something here.
            End If 
        Case Else 
            ' does some processing... 
            Exit Select 
    End Select
    

    Is there a reason for the goto? If it doesn't meet the if criterion, it will simply not perform the function and go to the next case.

    0 讨论(0)
  • 2020-12-11 00:42
    Select Case parameter
        ' does something here.
        ' does something here.
        Case "userID", "packageID", "mvrType"
                    ' does something here.
            If otherFactor Then
            Else
                goto case default
            End If
        Case Else
            ' does some processing...
            Exit Select
    End Select
    
    0 讨论(0)
提交回复
热议问题