我是C#的初学者,找不到任何答案:
我试图用一些接口参数委托动作,但推动使用扩展此接口(或类)的对象的函数
// some class extending interface
public class IntEvent : IFace{}
public class MoveEvent : IFace{}
// function i like to use to verify Action
static void setAction(Action<IFace> evt) {
// evt ...
}
// function to delegate as Action
static void evtCheck(IntEvent evt) {
// some func
}
static void evtMove(MoveEvent evt) {
// some func
}
// class {
// call method inside class and delegate this function :
setAction(evtCheck);
setAction(evtMove);
Run Code Online (Sandbox Code Playgroud)
即使扩展了界面,我也收到" evtCheck(IntEvent)无法转换为Action<IFace>" 的错误. …