C#C# · Lesson 1 of 9
Hello, World!
C# has evolved dramatically. Modern C# (12+) lets you write Hello World in one line. Old C# needed a class, a namespace, and a static void Main. We'll show both, but live in the modern world.
Modern C# (9+) supports "top-level statements" — you can write code directly without wrapping it in a class. The compiler generates the boilerplate for you. For reference, we'll also show the traditional form.
◆ Note
C# files have the .cs extension. A C# project is defined by a .csproj file. dotnet run handles compilation and execution. For production builds, use dotnet build then dotnet <project>.dll.
C# files have the .cs extension. A C# project is defined by a .csproj file. dotnet run handles compilation and execution. For production builds, use dotnet build then dotnet <project>.dll.