CKTIS / C#
Environment.ExitCode: practical reference
Environment.ExitCode: practical reference: Environment.ExitCode gets or sets the current process exit code returned to the operating system after normal termination.
Version: .NET API; verified on .NET 10.0.14
Syntax
Environment.ExitCode = intValueEnvironment.ExitCode gets or sets the current process exit code returned to the operating system after normal termination.
Use the property when the actual Main entry point returns void; the decision may then originate in a deeper layer. If Main returns int or Task, Environment.ExitCode is ignored, so propagate the process code through Main's return value. The documented void case does not cover Task Main.
Setting the value does not stop the process; later code still runs, while Environment.Exit stops immediately and can skip finally.
Code meaning and range are platform-specific and shells may retain only some bits; document nonzero codes rather than treating them as managed exceptions.
The complete program actually uses Environment.ExitCode; its exact expected stdout is 0.
Examples
using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;
Environment.ExitCode = 0;
Console.WriteLine(Environment.ExitCode);
Result
0
The complete program actually uses `Environment.ExitCode`; its exact expected stdout is `0`.