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 theSystemnamespace, whereConsolelives;namespaceis a "folder" for your own classes,class Programis a class, andMainis the entry point: execution starts there;- every statement ends with
;, and blocks go in curly braces{ }; - C# is case-sensitive:
Consoleandconsoleare 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.