Lesson 1 of 13
Hello, World!
Write and run your first C# program, in both the modern one-line style and the traditional form with a and a Main .
Modern C# (9+) supports "top-level statements" — you can write code directly without wrapping it in a class. The generates the boilerplate for you. For , we'll also show the traditional form.
// Modern C# (top-level statements) — Program.cs
Console.WriteLine("Hello, World!");// Traditional form (still valid, required in some contexts)
using System;
namespace HelloApp
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
Console.WriteLine("My name is {0} and I am {1}.", "Alice", 30);
// String interpolation (modern, preferred)
string name = "World";
Console.WriteLine($"Hello, {name}!");
Console.WriteLine($"2 + 2 = {2 + 2}");
// Console.Write — no newline
Console.Write("Loading");
Console.Write("...");
Console.WriteLine("done!");
}
}
}dotnet new console -n HelloWorld
cd HelloWorld
# Edit Program.cs, then:
dotnet runFinished reading?Mark it done to track your progress.
Tip: use the ← and → keys to move between lessons.