开发者

Func<T, TResult> for with void TResult?

Func<> is ve开发者_运维问答ry convenient in .NET. Is there a way i can specify the param type and have the result value as void? I'd like to pass void Write(string) as a parameter.


Action<T> - "Encapsulates a method that takes a single parameter and does not return a value"


I believe you're looking for the Action<T> family of delegate types.


It's not perfect, but sometimes when I want to fake this behavior against an existing function (and I'd rather not re-implement it as Action<TResult>) I'll just return null and throw the value away.

Func<T, TResult> myFunc = (inVar) =>
{
    // do work...

    return null as object;
};
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜