我想通过这个方法
private void activityStreamDownloaded(TaskNotification tn)
{
//Logic
}
使用Delegate ad = activityStreamDownloaded;
方法
public void AddNextTask(WebAPITask task, Delegate callback)
{
//Error: Callback is variable but is used like a method
task.OnExecuted += () => callback(task.TaskNotification);
}
喜欢这个_taskList.AddNextTask (new TaskObj(), ad);
为什么会发生这种情况,我该如何解决?
答案 0 :(得分:0)
正如评论中所指出的那样Delegate
是一个抽象类。而是尝试这样的事情;
// declare an action type (basically a delegate with void return type)
Action<TaskNotification> callback = activityStreamDownloaded;
// update method signature to take an Action<TaskNotification>
public void AddNextTask(WebAPITask task, Action<TaskNotification> callback)
// this code should work now
_taskList.AddNextTask (new TaskObj(), callback);