4
Answers

Events

Ask a question
Smart    Lucky

Smart Lucky

13y
1.3k
1
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)