Lesson 1 of 10

Your first program

Goal

The Main method, the Console class and string interpolation

01

Explanation

All C# code lives inside a class, and the program starts running at the static void Main() method. The line using System; at the top of the file brings in the ready-made tools from System, including Console.

Console.WriteLine prints text and then moves to a new line. To put a value inside a string, write a $ before the opening quote and put the value in curly braces, like this: $"Level {level}". This is called string interpolation.

Every method states the type of value it returns before its name, and the type of each parameter before that parameter's name, so static string Greet(string name) takes a string and returns a string. C# is a compiled language: the compiler checks all of your code before it runs, and if it finds even one type error, the program doesn't run at all and the compiler tells you which line the error is on.

02

Your task

Complete Greet(name) so it returns Hello, Layan! when the name is Layan: the words "Hello, " followed by the name and an exclamation mark. Then call it from Main to print a greeting for Layan, and press “Run and check” to see the result.

Checks

3 checks
  1. Greet("Sara") returns "Hello, Sara!"
  2. Greet works with any name
  3. Layan's greeting was printed
03

Hints

0/3
Track lessons0 of 10 done

C# is the language behind Unity games and .NET apps. Every variable has a fixed type, programs are built from classes, and it comes with ready-made tools for most of what you need.

Beginner level, 10 lessons, 2.5 hours in total.

Program.cs
OutputC# (Mono 6.6, Judge0)

Compiling and running your code on the server.

–/3

Compiling and running your code on the server.

3 checks listed under “Your task”.

Track lessons0 of 10 done

C# is the language behind Unity games and .NET apps. Every variable has a fixed type, programs are built from classes, and it comes with ready-made tools for most of what you need.

Beginner level, 10 lessons, 2.5 hours in total.