VC# Exit Sub Equivalent

In VB if I want to exit out of a procedure I call "Exit Sub".

What is the equivalent of doing so in VC# in a class library project in a procedure

Thanks,

Ryan


Answer this question

VC# Exit Sub Equivalent

  • Krad

    Ryan,

    That's what 'return' does. In the example above, the Console.WriteLine statement will not be run if value is equal to null or is an empty string (ie has a length of 0).



  • darentan

    Hi David,

    Thanks for your response.

    I was hoping to find something in VC# that stopped the procedure/function running after when it's Exit Sub equivalent was called.

    Eg...

    public void Testing(string value)
    {
    if (value == null || value.Length == 0)
    Exit Sub;

    // anything else below this is not run
    Console.WriteLine(value);
    }

    Thanks,

    Ryan

  • Willis777

    Ryan,

    Similar to VB.NET, C# uses return, for example:

    VB Sub Equivalent:



    public void WriteLine(string value)
    {
         if (value == null || value.Length == 0)
            return;
        
         Console.WriteLine(value);
    }

     

    VB Function Equivalent:



    public string Concat(string value1, string value2)
    {
        if (value1 == null || value1.Length == 0)
            return value2;
     
        if (value2 == null || value2.Length == 0)
            return value1;
     
        return value1 + ":" + value2;
    }

     



  • c3

    Oops.

    Thanks David.

  • VC# Exit Sub Equivalent