What is the difference between eventOne (with keyword ‘event’) and eventTwo (w/o keyword)?
class Program { public event EventHandler eventOne; public EventHandler eventTwo; public void RaiseOne() { if (eventOne != null) eventOne(this, EventArgs.Empty); } public void RaiseTwo() { if (eventTwo != null) eventTwo(this, EventArgs.Empty); } static void Main(string[] args) { var p = new Program(); p.eventOne += (s, e) => Console.WriteLine('One'); p.eventTwo += (s, e) => Console.WriteLine('Two'); p.RaiseOne(); p.RaiseTwo(); } }
eventOneis a public event backed by a private field of typeEventHandler.eventTwois a public field of typeEventHandler.Basically an event only encapsulates the ideas of ‘subscribe’ and ‘unsubscribe’ in the same way that a property only encapsulates the ideas of ‘get’ and ‘set’ rather than the actual storage. (As far as the CLR is concerned an event can also expose a ‘raise’ method, but C# never uses this. Ignore it.)
See my article on events (alternate link) for more about the difference between delegates and events.