C# - Environment.Exit() Method with Example

In this tutorial, we will learn about the C# Environment.Exit() method with its definition, usage, syntax, and example. By Nidhi Last updated : March 30, 2023

Environment.Exit() Method

The Environment.Exit() method is used to terminate the current process and return a specified exit code to the operating system.

Syntax

void Environment.Exit(int exitcode);

Parameter(s)

  • exitcode: exit code, that we want to return to the operating system. Here, 0 denotes success and non-zero denotes an error.

Return Value

This method does not return any value.

Exception(s)

  • System.Security.SecurityException

C# Example of Environment.Exit() Method

The source code to demonstrate the use of Exit() method of Environment class is given below. The given program is compiled and executed successfully.

using System;

class Sample
{
    //Entry point of Program
    static public void Main()
    {
        Console.WriteLine("Before Exit Function");
        Environment.Exit(0);
        Console.WriteLine("After Exit Function");
    }
}

Output

Before Exit Function
Press any key to continue . . .

C# Environment Class Programs »





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.