Use return; in your Main method.
If you are not in the main method, when you decide to exit the program, you need to return from the method that is currently being executed by the main method.
Example:
void Main(...) { DisplayAvailableCommands(); ProcessCommands(); } void ProcessCommands() { while(true) { var command = ReadCommandFromConsole(); switch(command) { case "help": DisplayHelp(); break; case "exit": return; } } }
This is actually not an example of a good overall console application design, but it illustrates the point.
Daniel Hilgarth
source share