Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exit a program with an exit code: C#

How to exit a program with an exit code in C#? In java it would be System.exit(int code);

like image 214
Louis Rhys Avatar asked Feb 03 '23 03:02

Louis Rhys


1 Answers

Either:

  • Declare your Main function as returning int, and return a value from it, or
  • Call Environment.Exit(int)

Returning a value from Main is a little nicer than exiting the process in the middle of a method, but this is presumably the same advice that applies to Java, C or C++.

like image 167
Tim Robinson Avatar answered Feb 05 '23 17:02

Tim Robinson