.net - Does anyone still use [goto] in C# and if so why? -
i wondering whether still uses "goto" keyword syntax in c# , possible reasons there doing so.
i tend view statements cause reader jump around code bad practice wondered whether there credible scenarios using such syntax?
there (rare) cases goto can improve readability. in fact, documentation linked lists 2 examples:
a common use of goto transfer control specific switch-case label or default label in switch statement.
the goto statement useful out of nested loops.
here's example latter one:
for (...) { (...) { ... if (something) goto end_of_loop; } } end_of_loop:
of course, there other ways around problem well, such refactoring code function, using dummy block around it, etc. (see this question details). side note, java language designers decided ban goto , introduce labeled break statement instead.
Comments
Post a Comment