C# events

C#
//To create a Event to while adhering the standard start at 1. and to only subcribe start at 4..
//1. Create a Event Arg	this can be in its own folder but should derive from EventArgs
// Note this should will need to be as exposed as your event and contain any data, info, or accessors you wish to pass to the even subscriber(user). But it is good pratice to keep all sets private or at least internal.
	/// <summary>
    /// An event argument to handle the Data received
    /// </summary>
    public class DataReceiveEventArgs : EventArgs
    {
        public byte[] Data { get; private set; }

        public DateTime DateTime { get; private set; } = DateTime.UtcNow;

        internal DataReceiveEventArgs(byte[] Data)
        {
            this.Data = Data;
        }
    }
//2. In the Class that will be raise (creates and orignates from) the event add a delegate EventHandler
// Note this should will need to be as exposed as your event. It should also conatin input for your above EventArgs class as e and object for the sender to match standards of best practice.
// This will basiclly determine the signature of any methods/functions subscribing to the event.
		/// <summary>
        /// A event delegate to handle the event
        /// </summary>
        /// <param name="Sender">a generalized object to hold the sender (rarely actually used except for loging)</param>
        /// <param name="e">the event arg with the Data for the event</param>
	public delegate void DataReceiveEventHandler(object Sender, DataReceiveEventArgs e);
//3. In the same class add the event as your events delegate signature.
	/// <summary>
    /// An event to handle the Received data
    /// </summary>
    public event DataReceiveEventHandler DataReceiveEvent;
//4. Subscribe in a constructor or some init method/function in a subscribing(using) class.
	YourClassInstance.DataReceiveEvent += DataRecivedEvent;
//5. Define the the Body of the subscribed method as matching the delegate's signiture
    private void DataRecivedEvent(object Sender, DataReceiveEventArgs e)
    {
      	//replace this with your code
      	throw new NotImplementedException();
    }


Source

Also in C#: