Today, I saw the use of delegation and events in a project, so I reorganized a simple and easy-to-understand example for reference only.
Namespace DelegateAndEvent {public delegate void delegateTest (int a); // defines a delegate public delegate void delegateErr (Exception e ); // define an error delegate class Program {static void Main (string [] args) {object r = Console. readLine (); class1 c = new class1 (); c. getTest + = new delegateTest (c_getTest); // Add the event Function c. getErr + = new delegateErr (c_getError); // Add the event Function c. start (r); Console. readKey ();} static void c_getTest (int a) {Console. writeLine ("the number you entered is:" + a);} static void c_getError (Exception e) {Console. writeLine (e. toString () ;}} public class class1 {public event delegateTest getTest = null; // defines an event public event delegateErr getErr = null; // defines an error event public class1 () {}////// Start execution //////Public void start (object a) {try {if (null! = GetTest) {getTest (Convert. ToInt16 (a) ;}} catch (Exception e) {getError (e );}}////// Error Reporting Mechanism //////Public void getError (Exception e) {if (null! = GetErr) getErr (e );}}}