Jump to content
  • Advertisement
Sign in to follow this  
nsto119

[.net] Event/delegate question...

This topic is 4443 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there a difference between: foo.Event += new EventHandler( bar ); and foo.Event += bar; ?

Share this post


Link to post
Share on other sites
Advertisement
Thanks. I knew the behaved the same way, but I wasn't sure if one was preferred to the other or something.

Share this post


Link to post
Share on other sites
On my dev team we tend to prefer the second form. However, one advantage of the first form is that VS will autogenerate the method signature of the handler for you.

Share this post


Link to post
Share on other sites
Note that the second is only legal in C#2. C#1 didn't do implicit delegate type discovery. So if you're planning on downlevel build support, avoid it.

Share this post


Link to post
Share on other sites
Also, if you're in the unlikely scenario of passing something to just a System.Delegate (arbitrary delegate) this:


System.Delegate Stuff+=delegate(string s){ /*...*/ };


doesn't work. Object return isn't assumed, and it can't otherwise determine.
Explicitly setting the type is required.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!