How would I convert C# delegate function to VB.Net?
Here there's an old question about this code.
xmpp.OnLogin += delegate(object o)
{
xmpp.Send(
new Message(
new Jid(JID_RECEIVER),
MessageType.chat,
"Hello, how are you?"
)
);
};
I want to use it in vb.net (version 10) but I couldn't figure out how to convert 开发者_运维百科it.
The delegate is an anonymous function. The syntax is a bit different for VB .NET, as expected. Without having the VB compiler at hand, I would say you need something like:
AddHandler xmpp.OnLogin,
Sub(o As Object)
xmpp.Send(
new Message(
new Jid(JID_RECEIVER),
MessageType.chat,
"Hello, how are you?"
)
End Sub
I don't know how to declare an anonymous delegate in VB.NET and I'm too lazy to Google it, but something like this should work (warning: not tested):
AddHandler xmpp.OnLogin, AddressOf Me.HandleSendMessage
Private Sub HandleSendMessage(ByVal o As Object)
xmpp.Send( new Message(
new Jid(JID_RECEIVER),
MessageType.chat,
"Hello, how are you?"
)
)
End Sub
精彩评论