delegate (2) 썸네일형 리스트형 delegate(대리자) using System; // Declare delegate -- defines required signature: delegate void SampleDelegate(string message); class MainClass { // Regular method that matches signature: static void SampleDelegateMethod(string message) { Console.WriteLine(message); } static void Main() { // Instantiate delegate with named method: SampleDelegate d1 = SampleDelegateMethod; // Instantiate delegate with anonymous m.. delegate(대리자) 델리게이트(Delegate)는 C의 함수 포인터와 비슷한 역할을 한다. 즉, 자기 자신이 실제로 하는 일은 없고, 단지 자기가 가리키고 있는 메서드(함수)를 호출하는 역할을 하는 것이다. 결국 델리게이트(Delegate)는 함수에 대한 참조를 저장 하는 것인데 이렇게 함수에 대한 참조를 가리키고 있다는 것으로 인해 불가능한 작업등이 가능해진다. 예를 들면 Delegete를 다른 함수의 인자로 넘겨주게 되면 그 함수는 델리게이트가 보내 주는 함수의 참조를 이용하여 실행 시점에 호출될 함수를 결정 할 수 있는 것이다. 대리자의 선언은 일반 함수의 선언과 비슷하나 함수 본문이 없고 delegate 라는 키워드를 사용한다는 점이 다르다. 델리게이트는 쓰레드와 이벤트에서 주로 이용 할 수 있다는 것은 참고로 알아.. 이전 1 다음