728x90
람다
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
using starcraft;
namespace starcraft
{
public class App
{
//1. 대리자 형식 정의
public delegate void DelHeroMoveComplete();
public App()
{
//2. 대리자 인스턴스화
DelHeroMoveComplete del = () => {
Console.WriteLine("영웅이 이동을 완료!!");
};
Hero hero = new Hero();
hero.Move(del);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace starcraft
{
internal class Hero
{
//생성자
public Hero()
{
Console.WriteLine("영웅을 생성했습니다.");
}
public void Move(App.DelHeroMoveComplete callback)
{
Console.WriteLine("이동중...");
Console.WriteLine("이동중...");
Console.WriteLine("이동중...");
Console.WriteLine("이동중...");
Console.WriteLine("이동완료");
callback();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
using starcraft;
namespace starcraft
{
public class App
{
public App()
{
//대리자 변수 정의
Action action;
//대리자 인스턴스화 (메서드 연결)
action = this.SayHello;
action = () => {
Console.WriteLine("Hello~");
}; //람다문
action();
}
void SayHello()
{
Console.WriteLine("안녕하세요");
}
}
}
'KDT > C# 프로그래밍' 카테고리의 다른 글
23/07/27 Action 대리자 (0) | 2023.07.27 |
---|---|
23/07/27 데이터매니저 데이터로드 (0) | 2023.07.27 |
23/07/27 대리자 (0) | 2023.07.27 |
23/07/27 전시간 수업 내용 정리 (0) | 2023.07.27 |
23/07/26 과제 및 가짜 인벤토리 복습(집에서) (0) | 2023.07.26 |