I am a VB programmer working my way into C#. I learned how to create and raise events in vb and am finding that it isnt done the same way in C#. Has anybody come across an article that will help me to understand how to do events in C# and maybe explain why it is different in VB.
Thanks
Does this help?
VB.NET vs. C# - Delegates / Events
The main difference is the syntax that's used. Underneath, they use the exact same mechanisms within the CLR.
However, VB.NET provides special syntax via WithEvents and Handles, allowing you to do:
Dim WithEvents button1 As Button
Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyButton.Click
' Handle button click
End Sub
C# doesn't provide an equivelent - all events must be explicitly subscribed to via event +=, which is more like VB.NET's AddHandler statement.
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