The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
Environment.Exit Method
.NET Framework 2.0
Terminates this process and gives the underlying operating system the specified exit code.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly: mscorlib (in mscorlib.dll)
The following code example shows the use of the Exit method to terminate program execution and return an exit code to the operating system.
// Example for the Environment.Exit( int ) method. using System; class ExitTest { public static void Main( ) { Console.WriteLine( "If this program is invoked with [{0}] " + "from the command prompt,", Environment.CommandLine ); String[ ] args = Environment.GetCommandLineArgs( ); // args[0] is the program name and, args[1] is the first argument. // Test for a command-line argument. if( args.Length > 1 ) { // Parse the argument. If successful, exit with the parsed code. try { int exitCode = int.Parse( args[1] ); Console.WriteLine( "it exits with code: 0x{0:X8}.", exitCode ); Environment.Exit( exitCode ); } // If the parse fails, you fall out of the program. catch { } } Console.WriteLine( "it exits by falling through." ); } } /* If this program is invoked with [EnvExit -2147480000] from the command prompt, it exits with code: 0x80000E40. */
// Example for the Environment.Exit(int) method.
import System.* ;
class ExitTest
{
public static void main(String[] args)
{
Console.WriteLine("If this program is invoked with [{0}] " +
"from the command prompt,", Environment.get_CommandLine());
String args1[] = Environment.GetCommandLineArgs();
// args[0] is the program name and, args[1] is the first argument.
// Test for a command-line argument.
if (args1.length > 1) {
// Parse the argument. If successful, exit with the parsed code.
try {
int exitCode = Integer.parseInt(args1[1]);
Console.WriteLine("it exits with code: 0x{0:X8}.",
((System.Int32)(exitCode)).ToString("X8") );
Environment.Exit(exitCode);
}
// If the parse fails, you fall out of the program.
catch(System.Exception exp) {
}
}
Console.WriteLine("it exits by falling through.");
} //main
} //ExitTest
/*
If this program is invoked with [EnvExit -2147480000] from the command prompt,
it exits with code: 0x80000E40.
*/
- SecurityPermission for the ability to call unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.