C#

클래스 반환 연습

s0002 2023. 1. 6. 11:46
using System;

namespace Study06
{
    class Program
    {
        static void Main(string[] args)
        {
            App app = new App();
        }
    }
}
using System;
using System.Collections.Generic;
using System.Text;

namespace Study06
{
    class App
    {
        public App()
        {
            Hero hero = new Hero();
            Monster monster = new Monster();
            Coin coin = monster.Die();
            hero.Get(coin);
        }
    }
}
using System;
using System.Collections.Generic;
using System.Text;

namespace Study06
{
    class Hero
    {
        public Hero()
        {
            Console.WriteLine("영웅생성");
        }

        public void Get(Coin coin)
        {
            Console.WriteLine("영웅이 코인을 얻었습니다");
        }
    }
}
using System;
using System.Collections.Generic;
using System.Text;

namespace Study06
{
    class Monster
    {
        public Monster()
        {
            Console.WriteLine("몬스터 생성");
        }

        public Coin Die()
        {
            Console.WriteLine("몬스터가 죽었습니다");
            Coin coin = new Coin();
            return coin;
        }
    }
}
using System;
using System.Collections.Generic;
using System.Text;

namespace Study06
{
    class Coin
    {
        public Coin()
        {
            Console.WriteLine("코인 생성");
        }
    }
}