I'm just going through our codebase at work, trying to clear the Warnings that get generated when compiled and there are a ton of "Function without As clause, clause" warnings.
While going back and changing most of these to be a Sub
instead of a Function
, I occasionally overlook a Return
statement because I just highlight the method name and look for a value assigned to it, which is how it's done in most of the code.
So I was just wondering if there's any difference between these:
Private Function Foo() As String
Foo = String.Empty
End Function
Or:
Private Function Foo() As String
Return String.Empty
End Function
Functionally, it seems to be identical but I wasn't sure if there was any behind the scenes differences in regards to how the compiler interprets this.
The main difference is that Return
exits the function while assigning a value to the function name does not. So the two equivalents should be
Private Function Foo() As String
Foo = String.Empty
Exit Function
'.....
End Function
Or:
Private Function Foo() As String
Return String.Empty
'.....
End Function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With