Is Exit Sub necessary or useful in VB.NET?

When using Sub, if I do not return a value, you must use:

Public Sub whatever() ... Exit Sub End Sub 

instead

 Public Sub whatever() ... End Sub 

Can I get anything (memory, speed, etc.) using "Exit"?

Does Sub exit anyway when it executes, even if I don't use the Exit operator?

Thanks.

+4
source share
1 answer

In this particular case, Exit Sub completely unnecessary. It can be used there, but is usually considered bad. A statement is necessary if you want to leave the method prematurely. For example, if you find that a certain condition is fulfilled and you do not want to execute the rest of the method

 Public Sub Example() If SomeCondition Then Exit Sub End If ' Do other work End Sub 
+13
source

Source: https://habr.com/ru/post/1499186/


All Articles