封装不带参数、带返回值的方法
我正在寻找类似 Action
I'm looking for something like Action<T> ("Encapsulates a method that has a single parameter and does not return a value") and like Func<T, TResult> ("Encapsulates a method that has one parameter and returns a value of the type specified by the TResult parameter"), but I have to encapsulate a method without parameter and with return value.
Is there anything, or I have to write one?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来您想要
Func
。Looks like you want
Func<TResult>
.Func 能够做到这一点。它有多种变体,具体取决于您需要的输入参数的数量,包括没有。不过,它始终采用返回类型,例如
Func
表示不带参数的函数,返回 int。希望这有帮助。
Func is capable of doing that. There are several variants of it, depending on the number of input parameters you're after, including none. It always takes a return type, though, e.g.
Func<int>
represents a function with no arguments, returning an int.Hope this helps.