|
-
Aug 29th, 2007, 10:41 PM
#1
Thread Starter
Just Married
[RESOLVED] [2.0] Exit and sub
Hi all
how to exit any function or sub in C# as we use exit sub and the exit function in vb.net!
-
Aug 29th, 2007, 11:07 PM
#2
Re: [2.0] Exit and sub
You should be shot for using Exit Function in VB and you should be kicked in the shins for using Exit Sub. Good programming practice dictates that you always and only ever use a Return statement to exit a method in VB. The same is true in C#, but fortunately it's enforced because there is no other way.
Also, note that there is no such thing as a Sub or procedure in C-based languages, including C#. All methods are functions and the equivalent of a VB procedure is a function with a void return type.
-
Aug 29th, 2007, 11:57 PM
#3
Thread Starter
Just Married
Re: [2.0] Exit and sub
Thanks That done
C# Code:
private void button1_Click(object sender, EventArgs e)
{
Boolean b=true;
if (b==true)
{
return ;
}
MessageBox.Show("s");
}
Last edited by shakti5385; Aug 30th, 2007 at 12:26 AM.
Reason: get the solution
-
Aug 30th, 2007, 12:26 AM
#4
Re: [2.0] Exit and sub
You don't return anything, which is the whole point of a void function. You just use the return statement on its own, exactly as you do in VB procedures:
VB.NET Code:
Private Sub SomeMethod()
Return
End Sub
C# Code:
private void function SomeMethod()
{
return;
}
-
Aug 30th, 2007, 12:28 AM
#5
Thread Starter
Just Married
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|