OnLogin on xmpp is probably an event declared as follows:
public event LoginEventHandler OnLogin;
where LoginEventHandler as the delegate type is probably declared as:
public delegate void LoginEventHandler(Object o);
This means that in order to subscribe to the event, you need to provide a method (or anonymous method / lambda expression ) that correspond to the subscription of the LoginEventHandler delegate.
In your example, you are passing an anonymous method using the delegate keyword:
xmpp.OnLogin += delegate(object o) { xmpp.Send(new Message(new Jid(JID_RECEIVER), MessageType.chat, "Hello, how are you?")); };
An anonymous method matches the delegate signature expected by the OnLogin event (return type is void + one object). You can also remove the object o parameter using contravariance , since it is not used inside the body of an anonymous method.
xmpp.OnLogin += delegate { xmpp.Send(new Message(new Jid(JID_RECEIVER), MessageType.chat, "Hello, how are you?")); };
Romain verdier
source share