Func delegate with ref variable

2019-01-09 08:21发布

public object MethodName(ref float y)
{
//method
}

How do I defined a Func delegate for this method?

2条回答
Rolldiameter
2楼-- · 2019-01-09 08:40

In .NET 4+ you can also support ref types this way...

public delegate bool MyFuncExtension<in string, MyRefType, out Boolean>(string input, ref MyRefType refType);
查看更多
smile是对你的礼貌
3楼-- · 2019-01-09 08:56

It cannot be done by Func but you can define a custom delegate for it:

public delegate object MethodNameDelegate(ref float y);

Usage example:

public object MethodWithRefFloat(ref float y)
{
    return null;
}

public void MethodCallThroughDelegate()
{
    MethodNameDelegate myDelegate = MethodWithRefFloat;

    float y = 0;
    myDelegate(ref y);
}
查看更多
登录 后发表回答