O'Reilly logo

From Java to C#: A Developer's Guide by Heng Ngee Mok

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

11.6. Flow control with the goto keyword

Yes, goto is still there in C#, although the makers of Java got rid of its functionality (still reserving the goto keyword) when they designed Java from C++. Nevertheless, do you realize that if you have been using labels in Java, and break-ing or continue-ing to such labels, you are actually performing a pseudo goto (without the goto keyword)?

There are three ways to use C#'s goto:

  • goto case <expression>;

  • goto <label>;

  • goto default;

11.6.1. Using goto in switch-case blocks

goto can be quite useful in switch-case blocks too, since 'falling-through' case blocks is no longer supported in C#.

Their use should be clear from this example (see section 11.4):

 1: using System; 2: 3: class TestClass{ 4: public static ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required