开发者

Func<T, TResult> for with void TResult?

开发者 https://www.devze.com 2022-12-21 05:30 出处:网络
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&

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

精彩评论

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

关注公众号