Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the preferred way of exiting a command line program?

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?

like image 422
toop Avatar asked Sep 13 '11 14:09

toop


People also ask

Which command is used to exit the program?

In computing, exit is a command used in many operating system command-line shells and scripting languages. The command causes the shell or program to terminate.

How do you exit a command in Linux?

Hold the Ctrl button and press the C key at the same time. It sends the SIGKILL signal to the running program to force quit the command.

Which command is used to terminate program immediately and return to command prompt?

Ctrl + C should stop a program running from the command prompt, similar to linux.


1 Answers

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:

Environment.Exit(0);

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.

like image 192
Davide Piras Avatar answered Sep 22 '22 18:09

Davide Piras