0

I want to call a label which is in method1 and the goto statement is in method2. Can I do this? if yes, How? I tried to this but it gives the error that the lable is found

  • 2
    Without seeing your code it is hard to say anything, but you need to rethink about the way you are going to do in the first place, as it is not recommended to use the `goto` statement nowadays, FYI. – Salah Akbari Apr 19 '20 at 07:44
  • @SalahAkbari my label is in the form load method and my goto statement is in btn click method.Why goto statement is not recommended? – Shreeram Gharote Apr 19 '20 at 07:50
  • what should i use instead of goto? – Shreeram Gharote Apr 19 '20 at 07:51
  • 2
    https://stackoverflow.com/questions/11906056/is-using-a-goto-statement-bad – Salah Akbari Apr 19 '20 at 07:52
  • _Why goto statement is not recommended?_ Because __it will lead to disaster__. The only reson to ever ever ever use it is to __jump forward__ out of a deeply nested loop. Your case is the opposite and a prime example of unstructured code. – TaW Apr 19 '20 at 08:16
  • @TaW Even that feels bad. The only reason I can think of is to purposefully direct C# to fall through a switch case which is otherwise forbidden (which just syntactically uses the `goto` keyword, not a label and jump). – Ray Apr 19 '20 at 11:02
  • _Even that feels bad_ Well, imo that's just our education. Once you have been there and tested the alternatives you learn to accept it. `Switch` always feels bad to me: All those ridiculousl `break` statements without any real puspose other than pimpering c coders.. – TaW Apr 19 '20 at 12:23

0 Answers0