locked
In vb.net there are the commands "Exit Sub" and "Goto". RRS feed

  • Question

  • User1316246260 posted

    In vb.net there are the commands "Exit Sub" and "Goto".  I can not find there analogous compatriots in c#.

    Monday, November 3, 2014 12:44 PM

Answers

  • User2103319870 posted

    You to can use the return instead of ExitSub in c#

    From MSDN:

    The return statement terminates execution of the method in which it appears and returns control to the calling method. It can also return an optional value. If the method is a void type, the return statement can be omitted.

    Sample Code

    static double CalculateArea(int r)
            {
                double area = r * r * Math.PI;
                return area;
            }

    You have the goto keyword in C# also.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 3, 2014 12:57 PM
  • User753101303 posted

    Hi,

    See http://msdn.microsoft.com/en-us/library/d96yfwee.aspx and in particular you'll find there the "return" and "goto" statements. The later one should be very rarely used. If used too much it likely points to some kind of code design issue.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 3, 2014 1:05 PM

All replies

  • User2103319870 posted

    You to can use the return instead of ExitSub in c#

    From MSDN:

    The return statement terminates execution of the method in which it appears and returns control to the calling method. It can also return an optional value. If the method is a void type, the return statement can be omitted.

    Sample Code

    static double CalculateArea(int r)
            {
                double area = r * r * Math.PI;
                return area;
            }

    You have the goto keyword in C# also.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 3, 2014 12:57 PM
  • User571301025 posted

    exit sub - You can use return for this purpose.

    goto - Exists in C# already : http://msdn.microsoft.com/en-us/library/13940fs2.aspx

    Monday, November 3, 2014 12:58 PM
  • User753101303 posted

    Hi,

    See http://msdn.microsoft.com/en-us/library/d96yfwee.aspx and in particular you'll find there the "return" and "goto" statements. The later one should be very rarely used. If used too much it likely points to some kind of code design issue.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 3, 2014 1:05 PM