A delegate is a type that holds a reference to a method in an object and is also a type-safe function pointer. Give you an example://declares a delegate, where NewDelegate () is understood to be a type that is then used to fetch the method. Delegate voidnewdelegate ();//The following is a two-way definition of a, B, which you can understand as a newdelegate of two instances of this type. Public voidA () {}; Public voidB () {}; Public voidMain () {newdelegate DGT1=NewNewDelegate (a); NewDelegate DGT2=NewNewDelegate (b);//DGT1 points to method a,dgt2 points to method B. That is, the return value of a method and the number of parameter types are declared with the delegate//match, you can invoke this method with a delegate. And the name of this method is passed as a parameter to the instantiated delegate.} event is a special kind of delegate, why do you say so? By deserializing the. NET Framework with the Anti-compilation tool, you can discover the definition of the event (this is just the definition of one of the events, the arguments for the event are defined differently in the class library), as follows: Public Delegate voidEventHandler (Objectsender, EventArgs e); And how do the click events of the various controls that are common are defined? Public EventEventHandler Click; Note The Click event is a delegate and one of our common button controls adds an event. Pageload: Button1.Click+=NewEventHandler (button1_click); Define events for Button1protectedButton1_Click (ObjectSender,eventargs e) {} As you can see, this is a typical delegate invocation.
What is a delegate in C # and whether the event is a delegate