Essential C# Keywords  Suggest an edit

event

An event allows the developer to implement a notification pattern.

Simple example

public class Server
{
    // defines the event
    public event EventHandler DataChangeEvent;

    void RaiseEvent()
    {
        var ev = DataChangeEvent;
        if(ev != null)
        {
            ev(this, EventArgs.Empty);
        }
    }
}

public class Client
{
    public void Client(Server server)
    {
        // client subscribes to the server's DataChangeEvent
        server.DataChangeEvent += server_DataChanged;
    }

    private void server_DataChanged(object sender, EventArgs args)
    {
        // notified when the server raises the DataChangeEvent
    }
}

MSDN reference


Table Of Contents
22 Enum
25 GUID
52 Keywords
107 Stream
108 Timers
  ↑ ↓ to navigate     ↵ to select     Esc to close