Created
August 3, 2018 19:23
-
-
Save perlun/ad14e60cead61c30780d2bcf60b2aa1b to your computer and use it in GitHub Desktop.
goto example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Foo | |
{ | |
// This program illustrates an arguable case where the usage of goto could be said to be warranted. | |
class Program | |
{ | |
private static int ParseArgumentsAndRun(string[] args) | |
{ | |
int returnValue; | |
if (args.Length != 1) | |
{ | |
DisplayUsage(); | |
returnValue = -1; | |
goto waitForKeypress; | |
} | |
var firstArg = args[0]; | |
switch (firstArg) | |
{ | |
case "/i": | |
case "/install": | |
returnValue = InstallService(); | |
break; | |
case "/u": | |
case "/uninstall": | |
returnValue = UninstallService(); | |
break; | |
default: | |
Console.WriteLine("Argument not recognized: {0}", args[0]); | |
Console.WriteLine(string.Empty); | |
DisplayUsage(); | |
returnValue = 1; | |
break; | |
} | |
waitForKeypress: | |
Console.WriteLine("Press any key to exit"); | |
Console.ReadKey(); | |
return returnValue; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment