Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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 
}

Live as if you were to die tomorrow. Learn as if you were to live forever.
Gandhi
Posted

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.

Live as if you were to die tomorrow. Learn as if you were to live forever.
Gandhi
  • Leaders
Posted
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.
[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...