开发者

Encapsulate method without parameters and with return value

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?


Looks like you want Func<TResult>.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜