CKTIS / C#
Main: practical reference
Main: practical reference: Main is the classic C# program entry point; valid signatures return void, int, Task, or Task<int>, optionally accept string[] args, and the compiler selects exactly one entry point.
Version: C# program entry point; verified with .NET SDK 10.0.403
Syntax
static void Main(string[] args) | static int Main(string[] args) | static Task Main(string[] args) | static Task<int> Main(string[] args)Main is the classic C# program entry point; valid signatures return void, int, Task, or Task, optionally accept string[] args, and the compiler selects exactly one entry point.
Use an explicit Main for a clear startup contract, arguments, asynchronous startup, or an exit code; top-level statements generate an entry point instead.
Multiple Main candidates require StartupObject; Main is case-sensitive, must be static, and should not hide exceptions without setting an error code and message.
args excludes the program name and may be empty; int or Task becomes the process code, while an unhandled exception terminates through a host-dependent path.
The complete program actually uses Main; its exact expected stdout is 0.
Examples
using System;
using System.Threading.Tasks;
public static class Program
{
public static int Main(string[] args)
{
Console.WriteLine(args.Length);
return 0;
}
}
Result
0
The complete program actually uses `Main`; its exact expected stdout is `0`.