带有 ref 变量的函数委托 [英] Func delegate with ref variable

查看:19
本文介绍了带有 ref 变量的函数委托的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

如何为这个方法定义一个 Func 委托?

How do I defined a Func delegate for this method?

推荐答案

Func 无法做到,但你可以为它定义一个自定义的delegate:

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

public delegate object MethodNameDelegate(ref float y);

使用示例:

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

public void MethodCallThroughDelegate()
{
    MethodNameDelegate myDelegate = MethodWithRefFloat;

    float y = 0;
    myDelegate(ref y);
}

这篇关于带有 ref 变量的函数委托的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆