Smart    Lucky

Smart Lucky

  • NA
  • 555
  • 639.4k

Events

Jul 7 2011 6:56 AM
Hi Dudes
Any one tell me

can any one tell me step by step the flow of this program .....?

namespace EventsInCSharp

{

    public class MyClass

    {

        public delegate void MyDelegate(string message);

        public event MyDelegate MyEvent;  // This is declaration of event 

 

        

        public void RaiseEvent(string message)

        {

            if (MyEvent != null)

                MyEvent(message); // is here we are calling the event.....?

        }

    }

    class Program

    {

        static void Main(string[] args)

        {

            MyClass myClass1 = new MyClass();

            myClass1.MyEvent += new MyClass.MyDelegate(myClass1_MyEvent);

 

            Console.WriteLine("Please enter a message\n");

            string msg = Console.ReadLine();

 

           

            myClass1.RaiseEvent(msg); // what is happining here is event is calling here....?

            Console.Read();

        }

       

        static void myClass1_MyEvent(string message)

        {

            Console.WriteLine("Your Message is: {0}", message);

        }

    }

}


Answers (4)