This should be straightforward. I just need to simply exit my commandline c# program - no fancy stuff.
Should I use
Environment.Exit();
or
this.Close();
or something else?
This should be straightforward. I just need to simply exit my commandline c# program - no fancy stuff.
Should I use
Environment.Exit();
or
this.Close();
or something else?
Use
return;
in yourMain
method.If you aren't in the main method when you decide to exit the program, you need to return from the method that Main method currently executes.
Example:
This is not really an example of good overall design of a console application, but it illustrates the point.
just return from the
Main
method.Edit:
if you really have lost the flow and want to exit from anywhere in the application (like inside any method called by Main), you can use:
remember that normally you should return 0 to the calling process (OS) when everything went fine and you return a non zero value if an error happened and execution did not go as smooth as should have been.