このプロセスを終了し、指定されている終了コードを基になるオペレーティング システムに渡します。
Public Shared Sub Exit( _
ByVal exitCode As Integer _)
[C#]
public static void Exit(intexitCode);
[C++]
public: static void Exit(intexitCode);
[JScript]
public static function Exit(
exitCode : int);
パラメータ
- exitCode
オペレーティング システムに渡される終了コード。
例外
例外の種類 | 条件 |
---|---|
SecurityException | 呼び出し元に、この関数を実行するための十分なセキュリティ許可がありません。 |
使用例
[Visual Basic, C#, C++] Exit メソッドを使用してプログラムの実行を停止し、オペレーティング システムに終了コードを返すコード例を次に示します。
' Example for the Environment.Exit( Integer ) method.
Imports System
Module ExitTest
Sub Main()
Console.WriteLine( _
"If this program is invoked with [{0}] " & _
"from the command prompt,", _
Environment.CommandLine)
Dim args As String() = 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 Then
' Parse the argument. If successful, exit with the parsed code.
Try
Dim exitCode As Integer = Integer.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
End Try
End If
Console.WriteLine("it exits by falling through.")
End Sub 'Main
End Module 'ExitTest
' If this program is invoked with [EnvExit -2147480000] from the command prompt,
' it exits with code: 0x80000E40.
[C#]
// 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.
*/
[C++]
// Example for the Environment::Exit( int ) method.
#using <mscorlib.dll>
using namespace System;
void main( )
{
Console::WriteLine(
S"If this program is invoked with [{0}] "
S"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 = Int32::Parse( args[1] );
Console::WriteLine(
S"it exits with code: 0x{0:X8}.",
__box(exitCode) );
Environment::Exit( exitCode );
}
// If the parse fails, you fall out of the program.
catch( Exception* e )
{ }
}
Console::WriteLine( S"it exits by falling through." );
}
/*
If this program is invoked with [EnvExit -2147480000] from the command prompt,
it exits with code: 0x80000E40.
*/
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, Common Language Infrastructure (CLI) Standard
.NET Framework セキュリティ:
- SecurityPermission (アンマネージ コードを呼び出すために必要なアクセス許可) SecurityPermissionFlag.UnmanagedCode (関連する列挙体)