C#/수업내용
03/22 델리게이트 연습 1
박준희
2021. 3. 22. 11:54
728x90

Program.cs
using System;
namespace Study07
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Program");
new App();
}
}
}
App.cs
using System;
namespace Study07
{
public class App
{
//생성자
public App()
{
Console.WriteLine("App");
Button btn = new Button();
//버튼을 눌렀다면 알려줘
btn.onClick = this.OnClickButton;
//유저가 버튼을 눌렀다
btn.Click();
}
public void OnClickButton()
{
//설정 팝업을 연다
Console.WriteLine("팝업창을 연다.");
}
}
}
Button.cs
using System;
namespace Study07
{
public delegate void Del();
public class Button
{
public Del onClick;
public Button()
{
}
public void Click()
{
Console.WriteLine("버튼을 클릭했습니다.");
this.onClick();
}
}
}
728x90