c# - 是否可以声明不带参数的通用委托(delegate)?

标签 c# generics delegates func

我有...

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/

相关文章:

c# - 将数字四舍五入,使其可以被 5 整除

c# - 与此 C# 片段等效的 UnityScript

swift - 为什么 Swift 不能自动将泛型类型参数转换为其父类(super class)?

Java 泛型类标记

javascript - 如何使用委托(delegate)事件?

c# - ServiceInterface 中的 ServiceStack Ormlite 使用

c# - 如何正确使用 StreamWriter 类?

C# 泛型函数

具有参数类型的 C# Func 委托(delegate)

ios - 将数据从没有 Segue 的 VC 传递到非 VC 类