Possible Duplicate:
Should I Create a New Delegate Instance?
Hi, I've tried searching for the answer to this, but don't really know what terms to search for, and none of the site-suggested questions are relevant. I'm sure this must have been answered before though.
Basically, can somebody tell me what's the difference between these two lines in C#:
SomeEvent += SomeMethod
SomeEvent += new SomeDelegate(SomeMethod)
For example:
DataContextChanged += App_DataContextChanged;
DataContextChanged += new DependencyPropertyChangedEventHandler(App_DataContextChanged);
They both seem to do the same thing.
Logo C merupakan sebuah lambang yang merujuk pada Copyright, yang berarti hak cipta.
C adalah huruf ketiga dalam alfabet Latin. Dalam bahasa Indonesia, huruf ini disebut ce (dibaca [tʃe]).
Meskipun C dibuat untuk memprogram sistem dan jaringan komputer namun bahasa ini juga sering digunakan dalam mengembangkan software aplikasi. C juga banyak dipakai oleh berbagai jenis platform sistem operasi dan arsitektur komputer, bahkan terdapat beberepa compiler yang sangat populer telah tersedia.
Bahasa pemrograman C ini dikembangkan antara tahun 1969 – 1972 oleh Dennis Ritchie. Yang kemudian dipakai untuk menulis ulang sistem operasi UNIX. Selain untuk mengembangkan UNIX, bahasa C juga dirilis sebagai bahasa pemrograman umum.
They are the same. The second variant is just a shorthand for the first called Method group conversion.
Simply put, the compiler infers what the type of the delegate is by using the delegate type of the event itself. This was introduced in C#2.0 if I'm not mistaken.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With