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 ...

Get From Java to C#: A Developer's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.