반응형
using System;
using System.Collections.Generic;
using System.Text;
//****************************************************************************
//  이벤트  
//****************************************************************************
// 특정 사건에 대한 알림 !! 
//  이벤트 처리기 ,  발생자 . 가입자  

namespace 이벤트
{
    class Button1
    {
        //  이벤트 발생하면 이벤트 처리함수를 저장하기 위한  대리자 !!  
        public delegate void MyDelegate(Object source, EventArgs e);
        // 이벤트 객체를 딜리게이트 객체와 함께 사용 !! 
        public static event MyDelegate myEvent;

        public static void CallEvent()
        {

            myEvent(  "ABC" , new EventArgs() ); 
        }

    }


    class Program
    {

        
        static void Main(string[] args)
        {

            Button1 btn1 = new Button1();
            Button1.myEvent += new Button1.MyDelegate(btn1_myEvent);
            Button1.CallEvent(); 

        }

        public static void btn1_myEvent(Object source, EventArgs e)
        {
            Console.WriteLine( source.ToString());
        }
    }
}

'C#' 카테고리의 다른 글

[C#] 인터페이스  (0) 2014.11.18
[C#] 인덱서  (0) 2014.11.18
[C#] 예외처리  (0) 2014.11.18
[C#] 생성자  (0) 2014.11.18
[C#] 상속  (0) 2014.11.18

+ Recent posts