← C# from Scratch Lesson 1 of 39 · 10 XP

Syntax

Theory and problem statement

Machine translation, not yet reviewed by a native speaker.

C# (pronounced "C sharp") is a language from Microsoft on the .NET platform. People use it to write Unity games, Windows programs, servers and mobile apps.

A classic program looks like this:

using System;

namespace HelloApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}
  • using System; — brings in the System namespace, where Console lives;
  • namespace is a "folder" for your own classes, class Program is a class, and Main is the entry point: execution starts there;
  • every statement ends with ;, and blocks go in curly braces { };
  • C# is case-sensitive: Console and console are different names.

Since C# 9 you can write top-level statements — the compiler wraps them in class Program and Main by itself:

using System;

Console.WriteLine("Hello World!");

In this course we write it this way — it's shorter, and classes will appear when we need them.

Under the hood. The Roslyn compiler turns a .cs file not into machine code but into IL (intermediate language) inside a .dll. When the program runs, the .NET runtime (CLR) translates IL into machine code as it goes — this is JIT compilation. Here C# is compiled and run on the server, in a sandbox.

Task. Print Hello World!.

Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.