使用函数退出sub的最佳实践



我正在寻找一种方法来编写一个函数,该函数将停止所有代码(exit-sub(,而不必为子程序中的函数编写If语句

例如:

Public Class Form_Main
Private Sub Button_Search_Click(sender As Object, e As EventArgs) Handles Button_Search.Click
If CountNumbers() = False Then Exit Sub 
' Is there a way for me to write "CountNumbers" only and it will
' [Exit Sub] without me having to write an if statement?
' Sort of embedding the Exit Sub in the function?
End Sub
Function CountNumbers()
Dim a As Integer = 1
If a = 1 Then
Return False
End If
Return True
End Function
End Class

使用Return关键字时不提供值

Public Sub Foo()
If Bar() = False Then
Return
End If
End Sub

最新更新