对于Action <>和/或Func <>,c#中的typedef等价

谷歌搜索后看起来并不乐观,但我想知道在使用Action< T>时是否存在某种混叠或类型定义方式.或者Func< in T,out TResult>在C#?

我已经看过Equivalent of typedef in c#了,它说在一个编译范围内你可以在某些情况下使用using构造,但就我所知,这似乎并不适用于Action和Func.

我想要这样做的原因是我想要一个动作用作多个函数的参数,如果我在某个时间点决定改变动作,那么很多地方都要改变它们作为参数类型和作为变量类型.

?typedef? MyAction  Action<int,int>;

public static SomeFunc(WindowClass window,int number,MyAction callbackAction) {
   ...
   SomeOtherFunc(callbackAction);
   ...
}

// In another file/class/...
private MyAction theCallback;

public static SomeOtherFunc(MyAction callbackAction) {
    theCallback = callbackAction;
}

是否有一些构造要使用,它可以定义代码段中指示的MyAction?

解决方法

在进行了一些搜索之后,似乎代表们正在拯救(见 Creating delegates manually vs using Action/Func delegatesA:
Custom delegate types vs Func and Action
).请评论为什么这不是解决方案或可能的陷阱.

有了代理,我可以重写给定代码示例的第一行:

public delegate void MyAction(int aNumber,int anotherNumber);
// Keep the rest of the code example

// To call one can still use anonymous actions/func/...
SomeFunc(myWindow,109,(int a,int b) => Console.Writeline);

相关文章

在要实现单例模式的类当中添加如下代码:实例化的时候:frmC...
1、如果制作圆角窗体,窗体先继承DOTNETBAR的:public parti...
根据网上资料,自己很粗略的实现了一个winform搜索提示,但是...
近期在做DSOFramer这个控件,打算自己弄一个自定义控件来封装...
今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都...
最近在研究WinWordControl这个控件,因为上级要求在系统里,...