Hello everyone:
I am currently having a hardtime understanding and implementing events in C# using delagates. I am used to the Java way of doing things:
- Define an interface for a listener type which would contain a number of method definitions
- Define adapter class for that interface to make things easier if I'm not interested in all the events defined in a listener
- Define Add, Remove and Get[] methods in the class which raises the events
- Define protected fire methods to do the dirty work of looping through the list of added listeners and calling the correct method
This I understand (and like!) - I know I could do this exactly the same in c#, but it seems that a new (better?) system is in place for c#. After reading countless tutorials explaining the use of delegates and events in c# I still am no closer to really understanding what is going on :S
In short, for the following methods how would I implement the event system in c#:
void computerStarted(Computer computer);
void computerStopped(Computer computer);
void computerReset(Computer computer);
void computerError(Computer computer, Exception error);
^ The above methods are taken from a Java application I once made which I'm trying to port over to c#.
Many many thanks!