Hello World

Create and run

dotnet new console -n HelloWorld
cd HelloWorld
dotnet run

Top-level statements (.NET 6+)

Your entire Program.cs:

Console.WriteLine("Hello, World!");

No Main method, no namespace, no class wrapper needed. The compiler generates the boilerplate.

With args and async

if (args.Length > 0)
{
    Console.WriteLine($"Hello, {args[0]}!");
}

await Task.Delay(1000);
Console.WriteLine("Done.");

Run with arguments:

dotnet run -- Alice

Project structure

HelloWorld/
├── Program.cs              # Entry point
├── HelloWorld.csproj       # Project config (target framework, packages)
└── bin/                    # Build output (gitignored)

The .csproj file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>
</Project>

Tip: ImplicitUsings auto-imports common namespaces (System, System.Collections.Generic, System.Linq, etc.) so you don’t need using statements for standard types.