我需要一些帮助来声明下面的 Subscribe() 方法。我几乎想拦截任何想要注册未来更新并告诉他们以前事件的人。
class Test
{
public delegate void OnCount(int nCount);
protected event OnCount _event;
Test()
{
_event += countHandler; // This subscribes ok
_event(6);
Subscribe(countHandler); // I would like to pass this
}
void countHandler(int n) { int m = n; }
void Subscribe(**Action<int>** callback) // Not sure how to declare argument (doesn't compile)
{
_event += callback; // Subscribe to future values (doesn't compile)
callback(5); // Pass current/previous values
}
}