gpt4 book ai didi

c# - 带有 ref 变量的 Func 委托(delegate)

转载 作者:IT王子 更新时间:2023-10-29 03:48:57 25 4
gpt4 key购买 nike

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

如何为该方法定义一个 Func 委托(delegate)?

最佳答案

它不能通过 Func 来完成,但你可以为它定义一个自定义的 delegate:

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

关于c# - 带有 ref 变量的 Func 委托(delegate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2462814/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com