Go to next statement - C#

Asked

Viewed 46 times

-2

I have a if and I need it to be true he gives the message below and soon after he pauses in the system or continues on another instruction. I left the word BREAK to illustrate where I need this encoding (but the BREAK doesn’t work):

if (lanceSelecionado.ID_LANCE == null)
{
  await DisplayAlert("Comunicado", "Selecione um lance para exclusão!", "Ok");
  BREAK;
}
  • 1

    If you give a return; it goes out of function, it does not solve?

  • the goto wouldn’t you? https://docs.microsoft.com/pt-br/dotnet/csharp/language-reference/keywords/goto

  • goto no! Hahhaha

  • Geez, the return did exactly what I expected. @Roberto, if you want to put as answer I define it as the best, I think it’s fair.

  • I posted the reply @Deividsouza, glad you solved your problem.

2 answers

2


You can use the return; if it is a return function void, for example:

public void NomeDaFuncao()
{
    if (lanceSelecionado.ID_LANCE == null)
    {
      await DisplayAlert("Comunicado", "Selecione um lance para exclusão!", "Ok");
      return;
    }
}

If it is a function with any kind of return it is necessary to do the return together with a default value, for example:

public int NomeDaFuncao()
{
    if (lanceSelecionado.ID_LANCE == null)
    {
      await DisplayAlert("Comunicado", "Selecione um lance para exclusão!", "Ok");
      return 0;
    }
}

The return has as function to return something and stop executing the function. It will only execute something else if it is inside a block try finally, in such cases whatever is within finally will be executed.

-1

Well your question is a little vague. If you wanted it to continue another instruction just call a method after Displayalert. If you wanted a stop in the application you can use System.Threading.Thread.Sleep(1000); or Console.ReadLine() (the application will return after pressing any key). Well has N ways to implement what you want and if you specify better we can help you in the most appropriate way.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.