开发者

Func delegate with ref variable

开发者 https://www.devze.com 2022-12-23 09:47 出处:网络
public object MethodName(ref float y) { // 开发者_如何转开发elided } How do I define a Func delegate for this method?It cannot be done by Func but you can define a custom delegate for it:
public object MethodName(ref float y)
{
    // 开发者_如何转开发elided
}

How do I define a Func delegate for this method?


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);
}


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);
0

精彩评论

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

关注公众号