我有...
Func<string> del2 = new Func<string>(MyMethod);
我真的很想做..
Func<> del2 = new Func<>(MyMethod);
所以回调方法的返回类型是void。这可能使用通用类型 func 吗?
最佳答案
Func
委托(delegate)系列适用于采用零个或多个参数并返回值的方法。对于采用零个或多个参数且不返回值的方法,请使用 Action
委托(delegate)之一。如果该方法没有参数,请使用 the non-generic version of Action
:
Action del = MyMethod;
关于c# - 是否可以声明不带参数的通用委托(delegate)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8414930/