What is "Exit Sub" in C#?

  • Thread starter Thread starter Brett
  • Start date Start date
Nice. Thanks.

Does this mean there is no concept of a method in C#? Everything is a
function?

Brett
 
Brett,
Methods are just functions that belong to objects. You are correct, there
are just Objects and not independent functions.
 
Not quite. In C#, there are simply methods that return values (functions in
VB) and those that don't (subs in VB). For example, the following two
procedures would be equivalent:

VB:
Public Sub DoesNothing()
Exit Sub 'Not required, but since it's what you originally asked
about... <g>
End Sub

C#:
public void DoesNothing()
{
return; // Not required here either.
}
 
Brett said:
What is the C# equivalent of VB.NET's Exit Sub?

Thanks,
Brett
Further to what everyone else has said, I would like to add that Exit
Sub is just a holdover from vb6 which should (my opinion) not be used as
Return (in vb.net) does the same thing and is more readable (especially
to non vb6 porgrammers).

I never liked the distinction between sub's and functions and think a
void return type is far cleaner and more readable.
Although I suppose
public function MyFunk() as void
is not that nice. :)

I suppose thats why I switched to c#.

My 2c

JB
 
John B said:
Further to what everyone else has said, I would like to add that Exit Sub
is just a holdover from vb6 which should (my opinion) not be used as
Return (in vb.net) does the same thing and is more readable (especially to
non vb6 porgrammers).

I never liked the distinction between sub's and functions and think a void
return type is far cleaner and more readable.

In this case, it's being used to break program flow. Not for returning
anything.

Brett
 
Brett said:
In this case, it's being used to break program flow. Not for returning
anything.

Brett
Which is also what return is used for.
Either
Return
(returns nothing)
or
Return value
(value)

VB.NET would (i presume) give a compile error if you tried to actually
return a value in a "sub".

JB
:)
 
Back
Top