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);
}
}
}

Zoran HorvatPosted Jul 19, 2011, 1:04 PM
Please don't forget to tick "this is correct answer" if you think that one of the posts answers your question.
Thanks,
Zoran
Vilas GitePosted Jul 19, 2011, 10:02 AM
What is an Events?
real life Example:
http://www.c-sharpcorner.com/Blogs/5927/events-in-C-Sharp-real-life-example.aspx
---------------------------------------------------------------------------------------------------
If this reply helps your post…then check "This is correct answer"
Vilas GitePosted Jul 7, 2011, 8:14 AM
Raised event. after looking your code, i just read Delegates & Events in c-sharp. @that time, i got one link which is described clearly.. nicely descried here.. refer:
http://www.akadia.com/services/dotnet_delegates_and_events.html
----------------------------------------------------------------------------------------------------
If this reply hepls your post…then "MARK AS ANSWER"!
Zoran HorvatPosted Jul 7, 2011, 7:05 AM
Program.myClass1_MyEvent
myClass1.RaiseEvent
Program.Main
This works as follows.
Main function invokes myClass1.RaiseEvent method. In that method event handler is invoked by literally "invoking" the event in line: MyEvent(message). Under the hood, this compiles into accessing the invocation list of the event MyEvent. This list at the moment contains only one item and that is reference (delegate) to method Program.myClass1_MyEvent. Hence, that method is immediately called. Should there be more handlers registered on MyEvent, those methods would be invoked as soon as Program.myClass1_MyEvent exits.
Zoran