c# - Simple question on anonymous method signatures and event handlers -


So, maybe a simple question with a simple answer, but I do not know what it is and I'm curious: ). Why does the compiler allow me to do something like this?

  button 1. Click + = Rep {someFlag = true; };  

(I can only use .NET 2.0, so no lamdas, but the same concept)

But I can not do this:

  button1. Click the + = MyDelegateMethod // snip // compilation error, the signature does not match the signature of System.EventHandler. Private zero to MyDelegateMethod () {}  

I expected that I would have to declare my anonymous method:

  Representative (Object Sender, EventAgages E) { SomeFlag = True; };  

I do not understand why this is right for an anonymous method, but when I write the whole method, then it is not okay. anyone?

The compiler can find out that your anonymous representative has the same type of button as the representative can click on But you do not need to use event arguments.

When you specify an actual method, the compiler "sees" that you are pointing a representative with an incorrect sign and therefore will not compile.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -