← C# from Scratch Lesson 27 of 39 · 5 XP

Warm-up: a hero warm-up

Theory and problem statement

Machine translation, not yet reviewed by a native speaker.

A class describes what an object is made of. public fields can be reached from outside with a dot, and an object is created with new:

Hero h = new Hero();
h.Name = "Kai";
h.Hp = 100;
Console.WriteLine($"{h.Name}: {h.Hp} HP");   // Kai: 100 HP

class Hero
{
    public string Name;
    public int Hp;
}

In a program with top-level statements, classes go after the statements.

Task. The Hero class is already there. Read a name and health (each on its own line) into the object's fields and print name: N HP.

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