C# Delegate from VB.NET
If that SelectedItemChanged
will only ever refer to a single delegate then just create one and assign it, just as you would for any other property referring to any other object:
MyObject.SelectedItemChanged = New SelectedItemChange(Sub(sender, args) DoSomething())
If it might refer to multiple delegates then you can do explicitly what the C# +=
operator is doing implicitly:
MyObject.SelectedItemChanged = [Delegate].Combine(MyObject.SelectedItemChanged, New SelectedItemChange(Sub(sender, args) DoSomething()))
It's worth noting here that your delegate is specific declared with two parameters of type IMyInterface
. That means that, in this code:
MyObject.SelectedItemChanged += (sender, args) => { DoSomething(); };
both sender
and args
are inferred as that type. They are NOT object
and EventArgs
, as you have assumed for your VB code. That's an example of how the C# code is garbage.
It´s because SelectedItemChange is not an event. You need to declare it as event
public event SelectedItemChange SelectedItemChange_Event;
Your AddHanler Syntax in VB is correct