Skip to content
dreamcode
dreamcode
Map
Hello, C#
Lesson 1 of 21
+15 XP on finish
C# FOUNDATIONSChapter 1 · C# Foundations

Your first C# program

C# code lives inside classes and methods. A program starts in a special method called Main. To print a line of text, you call Console.WriteLine. Newer project templates let you skip writing Main by using top-level statements, but the compiler still creates it for you behind the scenes.

Worked example
using System;

class Program {
    static void Main() {
        Console.WriteLine("Hello, sky!");
    }
}

How it reads

  • Console.WriteLine(...) prints a line of text to the console
  • static void Main() is where the program starts running
  • using System; brings in the namespace that contains Console
Cloud tip: C# statements end with a semicolon, and every line of code lives inside a class and a method.

Check your understanding

0 / 3

Answer all 3 to complete this lesson and earn 15 XP.

  1. 1. Which call prints a line of text to the console in C#?
  2. 2. Where does a C# program begin running?
  3. 3. What ends most C# statements?
Answer every question to unlock the next lesson.