All lessons

Your First Program

6 min · C#

Write and run your very first C# program, right here on the page.

C# · Your First Program0/5 cleared

Enemy 1 of 5

Classes, Main, and how a C# program starts

In C#, every bit of code lives inside a class — there's no such thing as a loose statement floating outside of one. class Program { ... } here is just a container; you could name it almost anything, but Program is the conventional name for the class that kicks things off.

Inside the class, static void Main() is the entry point — the method the runtime looks for and calls first when your program starts. static means Main belongs to the Program class itself rather than to an individual object of that class, which is why it can run immediately without anyone having to create a Program object first.

using System; at the very top imports the System namespace, which is where fundamental tools like Console (for reading and writing text) live. Namespaces in C# are how the huge .NET standard library stays organized instead of dumping every tool into one giant global pile.

You
Binary Treant

Loading editor...

Ln 1, Col 1Spaces: 4
Sign up to fightTarget output: Hello, World!