Skip to content

Instantly share code, notes, and snippets.

@perlun
Created August 3, 2018 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perlun/ad14e60cead61c30780d2bcf60b2aa1b to your computer and use it in GitHub Desktop.
Save perlun/ad14e60cead61c30780d2bcf60b2aa1b to your computer and use it in GitHub Desktop.
goto example
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