Exit sub

Tamer_Ahmed

Well-known member
Joined
Dec 20, 2003
Messages
159
Location
Egypt
hi in VB.net if u want exit the sub i use this word
Exit Sub but how can i use it in C# i cant use break; coz it work only with Loops can anybody help
 
Tamer_Ahmed said:
hi in VB.net if u want exit the sub i use this word
Exit Sub but how can i use it in C# i cant use break; coz it work only with Loops can anybody help
return is the .NET standard

use it instead of exit sub and exit function in VB as well.
thats the way it is done in virtually every other language. . .

Now, in some circles, using Goto and return are considered poor practice. In my algorithms class, 10 years ago, using a return to exit a void method would get you a big fat ZERO. The professors position was, if you are having to return to keep from executing unwanted code, your algorithm is passively defined and the compiler wont be able to optimize the method as well.

I dont know how much truth there is to that. I do use return occassionally but I dont make it a practice.
 
Back
Top