How to exit a method before ending in C #

2

What should I do to stop running a method before it finishes, quits, and continues execution?

public void MEUMETODO()
{

   ...

   PARA E SAIR AQUI();

   ...


}
    
asked by anonymous 21.05.2015 / 18:11

1 answer

6

There are two ways to exit / terminate the function:

  • return
  • Throw

You can use return; at any time to end the function:

public void MEUMETODO()
{    
   ...

   return;

   ...    
}

Or use Throw when an exception occurs:

public void MEUMETODO()
{    
   try
   {
       ...
   }
   catch (Exception)
   {                    
       throw;
   }
}
    
21.05.2015 / 18:14