델리게이트란? 델리게이트와 함수포인터 : http://hijuworld.tistory.com/39


델리게이트(delegate) 체인은 하나의 델리게이트 안에 여러개의 함수를 연결하여 연쇄적으로 호출하는 방식이다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
delegate void testDele();
static void Main(string[] args)
{
            
    void print1()
    {
        Console.WriteLine("print1");
    }
    void print2()
    {
        Console.WriteLine("print2");
    }
    void print3()
    {
        Console.WriteLine("print3");
    }
    testDele dele = new testDele(print1);
    dele += new testDele(print2);
    dele += new testDele(print3);
    dele();
}
cs


- 출력 -

print1

print2

print3


위에서 보듯이 print1함수와 print2, print3 함수들을 델리게이트 testDele에 +=로 추가를 하고 dele()로 호출을 하니 넣은 순서대로 3개 함수가 모두 호출되는 것을 볼 수 있다.

Posted by 꿈만은공돌
,