Results 1 to 5 of 5

Thread: [RESOLVED] [2.0] Exit and sub

  1. #1

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Resolved [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!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Thumbs up Re: [2.0] Exit and sub

    Thanks That done

    C# Code:
    1. private void button1_Click(object sender, EventArgs e)
    2.         {
    3.             Boolean b=true;
    4.             if (b==true)
    5.             {
    6.                 return ;
    7.             }
    8.             MessageBox.Show("s");
    9.         }
    Last edited by shakti5385; Aug 30th, 2007 at 12:26 AM. Reason: get the solution

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. Private Sub SomeMethod()
    2.     Return
    3. End Sub
    C# Code:
    1. private void function SomeMethod()
    2. {
    3.     return;
    4. }
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: [2.0] Exit and sub

    Thanks sir

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width