Environment.Exit メソッドとは? わかりやすく解説

Environment.Exit メソッド

このプロセス終了し指定されている終了コードを基になるオペレーティング システム渡します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

例外例外
例外種類条件

SecurityException

呼び出し元に、この関数実行するための十分なセキュリティ許可がありません。

使用例使用例

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.
// 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.
using namespace System;
int main()
{
   Console::WriteLine( "If this program is invoked with [{0}]
 "
   "from the command prompt,", Environment::CommandLine );
   array<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( "it exits with code: 0x{0:X8}.", exitCode
 );
         Environment::Exit( exitCode );
      }
      // If the parse fails, you fall out of the program.
      catch ( Exception^ e ) 
      {
      }

   }

   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.
*/
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「Environment.Exit メソッド」の関連用語

Environment.Exit メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Environment.Exit メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS