본문 바로가기

C#/수업 내용

대리자 연습 3

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HelloWorld
{
    class App
    {
        public delegate void Del(string animeName);

        //생성자
        public App()
        {
            Hero hero = new Hero();
            hero.onComplete = this.OnHeroAnimationComplete;
            hero.PlayAnimation("Idle");
        }

        void OnHeroAnimationComplete(string animeName)
        {
            Console.WriteLine(animeName);
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HelloWorld
{
    class Hero
    {
        public App.Del onComplete;

        //생성자
        public Hero()
        {

        }

        public void PlayAnimation(string animeName)
        {
            this.onComplete(animeName);
        }
    }
}

'C# > 수업 내용' 카테고리의 다른 글

대리자 연습 5  (0) 2021.12.24
대리자 연습4  (0) 2021.12.24
대리자 연습 2  (0) 2021.12.24
1-2주차 복습 (꿈의나라)  (0) 2021.12.24
상속 연습 하기  (0) 2021.12.24