Lesson 1 of 34 · Fundamentals
C# Hello World: Your First Program
Welcome to the Sharpforge Citadel! Every programmer's journey starts the same way: by making the computer say hello. In this first lesson you will write, compile and run a real C# program — right here in your browser, with nothing to install.
C# (pronounced C sharp) is a modern, general-purpose language created by Microsoft. It runs web APIs and cloud services on .NET, powers games built with Unity, and builds desktop and mobile apps. It is strict enough to catch your mistakes early and friendly enough to read like plain English.
Your first C# program
Here is a complete C# program:
Console.WriteLine("Hello, World!");
When you run it, it prints:
Hello, World!
Let's take it apart:
Consoleis a built-in class that represents the console — the text output you see below the editor.WriteLineis a method ofConsole: it writes a line of text and then moves to the next line. The dot.means "theWriteLinethat belongs toConsole"."Hello, World!"is a string — a piece of text in double quotes.- The semicolon
;ends the statement. C# needs it after almost every statement.
Top-level statements and the Main method
A program written like the one above uses top-level statements: the compiler runs your statements from top to bottom. Behind the scenes it wraps them in a method called Main, the entry point of every C# program. In older code (and in many tutorials) you will see that method written out by hand:
public class Program
{
public static void Main()
{
Console.WriteLine("Hello, World!");
}
}
Both versions do exactly the same thing. Top-level statements are simply less typing, so we use them for small programs. Later in this course, when you write methods and classes, you will see the full form again.
Compiling and running
C# is a compiled language. When you press Run, the C# compiler (called Roslyn) checks your code and translates it into instructions for the .NET runtime, which then executes it. If the compiler finds a mistake — a missing semicolon, a typo in a name — the program never starts. Instead you get a compile error with a line and column number, like (1,35): error CS1002: ; expected. Errors are normal: professional developers see them all day. Read the message, go to the line, fix it and run again.
Write vs WriteLine
Console.WriteLine ends the line; Console.Write does not, so the next output continues on the same line:
Console.Write("Level ");
Console.Write(1);
Console.WriteLine("!");
Console.WriteLine("Ready.");
Level 1!
Ready.
Comments
Comments are notes for humans; the compiler ignores them.
// A single-line comment runs to the end of the line.
/* A block comment
can span several lines. */
Console.WriteLine("Comments are ignored"); // this part too
Common mistakes
- Forgetting the semicolon:
Console.WriteLine("Hi")fails with; expected. - Wrong capitalisation: C# is case-sensitive.
console.writelinewill not compile — the class isConsoleand the method isWriteLine. - Single quotes around text:
'Hello'is not a string in C#. Single quotes are only for a single character, like'A'.
Assignment
Write a program that prints exactly these two lines:
Hello, World!
I'm learning C#!
Replace the starter line with two Console.WriteLine statements. The output must match exactly — capital letters, spaces, punctuation and the apostrophe in I'm all count.
Hello World in other languages
- Hello, World! Your First JavaScript Program · JavaScript
- Python Hello World: Your First Program · Python
- Go Hello World: Your First Go Program · Go
- Java Hello World: Your First Program · Java
Need a quick reminder? The C# cheat sheet has every topic of Learn C# on one page.
Lesson last updated on .