Learning C# Classes with a Story – Seojun and Jia’s Day ๐Ÿง™‍♂️

 

๐Ÿ‘ฆ The Tale of Class and Instance

Once upon a time, there was a magical blueprint called Person.

This blueprint described how a person behaves:

  • They have a name.

  • They can eat.

  • They can sleep.

  • They can work.

This blueprint is called a class in programming.

But a class is just an idea until we use it to make something real — like creating Seojun and Jia from the Person class.
These are called instances.




๐Ÿ”ฎ The Magical Code


using System;


class Person {

    public string Name;


    public Person(string name)

    {

        Name = name;

    }


    public void Eat()

    {

        Console.WriteLine(Name + " is eating.");

    }


    public void Sleep()

    {

        Console.WriteLine(Name + " is sleeping.");

    }


    public void Work()

    {

        Console.WriteLine(Name + " is working.");

    }

}


class Program {

    public static void Main (string [] args)

    {

        Person p1 = new Person("Seojun");

        Person p2 = new Person("Jia");


        p1.Eat();

        p2.Eat();

        p1.Sleep();

        p1.Work();

    }

}

๐Ÿ“ค Console Output

Seojun is eating. Jia is eating. Seojun is sleeping. Seojun is working.

Let’s Break It Down

Term Meaning Example
Class A blueprint for an object Person is a class for people
Instance A real object made from class p1 and p2 are people from Person class

๐ŸŽฎ Game Idea

  • The Person class is your player character.

  • Eat() → recover HP (health)

  • Sleep() → rest/save point

  • Work() → complete quests or earn coins

Each character (instance) could have different traits and routines!







Comments