38

What is the C# equivalence for System.exit(0); ?

Thanks

JAN
  • 21,236
  • 66
  • 181
  • 318

2 Answers2

74

If you are using a Console Application -

Environment.Exit(exitCode);

Else if you are using a Windows Forms based application -

Application.Exit();

Courtesy: http://www.dreamincode.net/forums/topic/273503-java-systemexit0%3B-equivalent-in-c%23/

Kamlesh Arya
  • 4,864
  • 3
  • 21
  • 28
11

You can use Environment.Exit(0) instead. Note that this is somewhat more complicated than Java due to some permissions issues, but in general this is the symmetrical equivalent.

You can read more about the possible Exceptions thrown in the linked documentation.

asteri
  • 11,402
  • 13
  • 60
  • 84