node-clr
node-clr copied to clipboard
Events and delegate types
Can we use delegates like below, is there an equivalent of this using CLR? If so, how would I go about doing that?
using System;
namespace SampleApp {
public delegate string MyDel(string str);
class EventProgram {
event MyDel MyEvent;
public EventProgram() {
this.MyEvent += new MyDel(this.WelcomeUser);
}
public string WelcomeUser(string username) {
return "Welcome " + username;
}
static void Main(string[] args) {
EventProgram obj1 = new EventProgram();
string result = obj1.MyEvent("AtsushiSuzuki");
Console.WriteLine(result);
}
}
}
You can consume .NET events by event.add(callback)
and event.remove(callback)
.
You cannnot define .NET events (this is by design), or invoke an event (not implemented).