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.


void Environment.Exit(int exitcode);


  • 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.


  • 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");
        Console.WriteLine("After Exit Function");


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.