Sign in to follow this  
nsto119

[.net] Event/delegate question...

Recommended Posts

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this