techmanbd Posted April 10, 2008 Posted April 10, 2008 I was wondering if it is proper to use the return in a void method to get of of the method as you would use exit sub in VB. It works I know that, but is it the proper way? For example VB private sub WWWW() if intL = 0 then exit sub ' other code here is intL not 0 End Sub private void WWWW() { if(intL == 0) { return; } // other code here if intL not 0 } Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
techmanbd Posted April 11, 2008 Author Posted April 11, 2008 Ok thanks, I am learning the C# language and read the following in the help files. But after reading it again, I realized that that goes for the expression after the return word. Duh. :o expression The value returned by a method. The expression is not used with methods of the type void. Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
Leaders snarfblam Posted April 11, 2008 Leaders Posted April 11, 2008 Some people, probably not many, equate using a return statement as a control-flow structure with using a goto statement: a mortal sin these days. (In other words, a return statement should only be used as the last statement in a non-void method.) I say use whatever makes your code the simplest. If that's a return in the middle of a function, fine by me. Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.