위 사진을 수정하세요.
-----------------------------------------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Helloworld
{
class App
{
//생성자
public App()
{
Blacksmith blacksmith = new Blacksmith();
blacksmith.CreateWeapon("장검", this.CreateWeaponHandler);
}
public void CreateWeaponHandler(Weapon weapon)
{
Console.WriteLine("created weapon: {0}", weapon.name);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Helloworld
{
class Blacksmith
{
public delegate void Del(Weapon weapon);
public Blacksmith()
{
}
public void CreateWeapon(string itemName, Del callback)
{
Weapon weapon = new Weapon(itemName);
callback(weapon);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Helloworld
{
class Weapon
{
public string name;
public Weapon(string name)
{
this.name = name;
}
}
}
이번껀 너무 어렵다..
-웨폰 클래스를 생성하는 타이밍도 잘 모르겠다;
-출력에서 callback 을 안쓰고 하려다보니 이해 자체가 안갔다; 결국 선생님 코드 확인..
-itemName은 몰랐는데 계속 보다보니까 weapon을 사용 한 것.
-호출에서 callback(); 사용 기억 (단, 매개변수에 콜백을 넣고 나서)
-웨폰을 생성했으니까 클래스도 생성.
하여튼 어렵다;;
'c# > 복습 공부' 카테고리의 다른 글
람다식 연습 2번(Action) (0) | 2021.09.07 |
---|---|
람다식 연습 1번(Action) (0) | 2021.09.07 |
대리자 응용 복습 (문제 3) (0) | 2021.09.07 |
대리자 응용 복습 (문제 2) (0) | 2021.09.06 |
대리자 응용 복습 (문제 1) (0) | 2021.09.06 |