Var handler = MyEvent on VB.net

I have a question about his article .

I converted the source code to Vb.net, but I have a problem with this line:

 var handler = MyEvent

Can someone help me translate this string to VB.net?

+1
source share
3 answers
var handler = MyEvent;
if (handler == null)
{
    Console.WriteLine("No listeners");
    return;
}

can translate to

Dim handler = MyEventEvent
If handler Is Nothing
     Console.WriteLine("No listeners")
     Return
End If

enter image description here

+3
source

You need to declare a custom event with the Custom keyword to access the base delegate. This is well explained in this MSDN library article .

, catching, , . , , . - . , , , , . , . catch , , . , .

0

I think it will be either

Dim handler As EventHandler = MyEvent

or

Dim handler As EventHandler = AddressOf MyEvent
-1
source

Source: https://habr.com/ru/post/1628866/


All Articles