Vb.net 使用块退出
我有类似的代码:Vb.net 使用块退出,vb.net,Vb.net,我有类似的代码: Using conn As OdbcConnection = getNewConnection() '' Some code If breakFlag Then canExit = True GoTo exitUpdate End If exitUpdate: End Using 我想摆脱GOTO语句。 因为有ExitUsing命令会很方便,但我们没有 在类似情况下使用block退出是否有一些好方法,或者我必须以不同的方式设计代码 与While或Fo
Using conn As OdbcConnection = getNewConnection()
'' Some code
If breakFlag Then
canExit = True
GoTo exitUpdate
End If
exitUpdate:
End Using
我想摆脱GOTO语句。因为有ExitUsing命令会很方便,但我们没有
在类似情况下使用block退出是否有一些好方法,或者我必须以不同的方式设计代码 与
While
或For
循环不同,使用块的实际上不是一种控制结构。它只是Dispose
模式的包装器。因此,可能有或可能没有理由使用
块在之外执行任何操作,这取决于您的代码应该执行的操作。
Using conn As OdbcConnection = getNewConnection()
'' Some code
If breakFlag Then
canExit = True
' remove this: GoTo exitUpdate
ELSE
' here place the rest of your logic that would execute when breakflag = false
End If
End Using