• .NET의 Delegate 연쇄호출(Chain) 등록 및 해제
- 델리게이트에 함수를 등록 하게 되면, 메소드를 사용 할때마다, 등록 되어있는 함수 전부에 메세지가 날라감, 필요에 따라서 델리게이트에 등록된 메소드를 해제 하면, 해제한 메소드 를 제외한 등록되어 있는 메소드들에게 메세지가 날라감.
- 반환형은 반드시 void 로 되어있어야함.
• ExamDelegate02.cs
/**
* @file ExamDelegate02.cs
* @brief 델리게이트 연쇄호출(Chain) 예제.
* @details 델리게이트 연쇄호출(Chain) 사용법.
* @version 0.0.1
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StudyCSharp_Bong9
{
namespace ExamDelegate02
{
/**
* @brief 델리게이트 연쇄호출(Chain) 클래스.
* @author 김봉재.
* @date 2014-08-07
*/
class ExamDelegate
{
///@brief Delegate 연쇄호출 등록을 위해서는 void 형식이어야함.
delegate void DelegateMethod(int a);
static void Method1(int a)
{
Console.WriteLine("Method1 이 호출. a : {0}", ++a);
}
static void Method2(int a)
{
Console.WriteLine("Method2 이 호출. a : {0}", ++a);
}
static void Method3(int a)
{
Console.WriteLine("Method3 이 호출. a : {0}", ++a);
}
static void Main(params string[] args)
{
DelegateMethod method = null;
///@brief Delegate 연쇄호출 등록.
method += Method1;
method += Method2;
method += Method3;
///@brief Delegate 연쇄호출 삭제.
method -= Method1;
///@brief Delegate 실행.
method(0);
}
}
}
}
게시자: bong9
UnrealEngine4, Unity3d, vr, gameprogrammer
bong9의 모든 글 보기