Skip to content

Program.cs entry point

Program.cs contains the entry point of your .NET application—the code that runs first when the application starts.

using System;
namespace MyApp
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
// No namespace, no class, no Main method
Console.WriteLine("Hello World!");
// With top-level statements
if (args.Length > 0)
{
Console.WriteLine($"Hello {args[0]}!");
}