← Back to C# Course | Chapter 1: Setup & Basics | Lesson 3 of 7

Hello World

Hello World is the very first program most people write, a tiny one that just prints a greeting. It is like your first wave hello to the computer, and every C# program has a starting spot called Main.

In this page:

  1. Hello World
Syntax
csharp
using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("text");
    }
}

Hello World

Every C# program starts execution in a Main method inside a class. Console.WriteLine prints text to standard output followed by a newline. This is the traditional first program used to confirm your setup works.

Note: The using System; line imports the namespace that contains Console.

Example: Hello World

markup
using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Hello, World!");
    }
}
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Forgetting the semicolon at the end of Console.WriteLine("Hello");, which gives a compile error.
  2. Writing console.writeline in lowercase, when C# is case-sensitive and the name is Console.WriteLine.
  3. Running the .cs file directly instead of building and running the project with dotnet run.
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.