[英]Func delegate with ref variable
public object MethodName(ref float y)
{
//method
}
如何為該方法定義Func委托?
它不能由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);
}
在.NET 4+中,您還可以通過這種方式支持ref
類型...
public delegate bool MyFuncExtension<in string, MyRefType, out Boolean>(string input, ref MyRefType refType);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.