Your First C# Program
Scaffolding, running, and understanding a minimal "Hello, World" console app.
2 min read
With the SDK installed, let's create and run an actual program.
Scaffolding the project
dotnet new console -o HelloWorld
cd HelloWorld
dotnet runThis generates a folder with a .csproj file and a Program.cs file, and dotnet run prints:
Hello, World!
What's actually in Program.cs
Open Program.cs and you'll see something surprisingly short:
Console.WriteLine("Hello, World!");That's it — one line. If you've seen C# before, you might expect a class Program with a static void Main wrapping that line. Modern C# (since C# 9) supports top-level statements: for a simple program, the compiler generates that boilerplate for you behind the scenes. It's still there at compile time, just not something you have to type for small programs.
The traditional, fully explicit form looks like this, and you'll still see it in larger real-world projects:
using System;
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
}
}Main is the entry point every .NET program needs somewhere — top-level statements just let the compiler infer it for you.
Reading input
Console handles both directions:
Console.Write("What's your name? ");
string? name = Console.ReadLine();
Console.WriteLine($"Hello, {name}!");Console.ReadLine() blocks until the user types something and hits Enter, returning it as a string. Note the string? — ReadLine() can return null if input ends unexpectedly (like piping in an empty stream), and the ? is C#'s way of documenting that upfront. You'll cover exactly what that means in the nullable types lesson.
The $ string and building blocks
That $"Hello, {name}!" is a string interpolation — the $ prefix lets you embed expressions directly inside {} in a string, instead of concatenating with +. You'll use this constantly; it's more readable than "Hello, " + name + "!" and it's the idiomatic way to build strings in modern C#.
From here, every concept in this course — variables, types, control flow, classes — builds on this same loop: write code, dotnet run it, see the result.
Test what you just learned
4 quick questions. Get all of them right to unlock the next lesson.
You can take the quiz without an account — logging in just lets your result count toward your progress.