Codiqo

Learn C# · lesson 1 of 61 · about 5 minutes

Hello, C#

Start a turn-based battle: print the arena's opening lines with Console.WriteLine, and fix your first compiler error.

What you'll learn

  • Print with Console.WriteLine
  • Use Console.Write without a new line
  • Read a compiler error and find the line

Enter the arena

C# runs the game logic of thousands of Unity games, from small phone games to big hits, and Windows apps and web services too. In this unit you'll start a turn-based battle: you and a monster take turns until one of you runs out of health.

A modern C# program can start with top-level statements: you write the code, and it runs from the top, line by line.

The battle begins

Console.WriteLine("=== Arena ===");
Console.WriteLine("A wild Slime appears!");

Output

=== Arena ===
A wild Slime appears!

Write and WriteLine

  • Console.WriteLine(...) prints and then starts a new line
  • Console.Write(...) prints without starting a new line
  • Text goes in double quotes, and every statement ends with ;
  • C# is case-sensitive: console.WriteLine won't compile

Write stays on the same line

Console.Write("Charging");
Console.Write("...");
Console.WriteLine(" done");
Console.WriteLine("Fight!");

Output

Charging... done
Fight!

Now try it yourself

This lesson is free in Codiqo, with 7 questions on what you just read. You can only learn to code by writing code, so it ends with a short program you write yourself, which we run and check straight away.