snippetcsharpCritical
How do I specify the exit code of a console application in .NET?
Viewed 0 times
nethowconsoletheexitspecifyapplicationcode
Problem
I have a trivial console application in .NET. It's just a test part of a larger application. I'd like to specify the "exit code" of my console application. How do I do this?
Solution
Three options:
Depending on your application (console, service, web application, etc.), different methods can be used.
- You can return it from
Mainif you declare yourMainmethod to returnint.
- You can call
Environment.Exit(code).
- You can set the exit code using properties:
Environment.ExitCode = -1;. This will be used if nothing else sets the return code or uses one of the other options above).
Depending on your application (console, service, web application, etc.), different methods can be used.
Context
Stack Overflow Q#155610, score: 740
Revisions (0)
No revisions yet.