chu*_*h97 52 c# delegates reference func c#-3.0
public object MethodName(ref float y)
{
//method
}
Run Code Online (Sandbox Code Playgroud)
如何为此方法定义Func委托?
Eli*_*sha 83
它无法完成,Func但你可以delegate为它定义一个自定义:
public delegate object MethodNameDelegate(ref float y);
Run Code Online (Sandbox Code Playgroud)
用法示例:
public object MethodWithRefFloat(ref float y)
{
return null;
}
public void MethodCallThroughDelegate()
{
MethodNameDelegate myDelegate = MethodWithRefFloat;
float y = 0;
myDelegate(ref y);
}
Run Code Online (Sandbox Code Playgroud)
在.NET 4+中,您也可以通过ref这种方式支持类型...
public delegate bool MyFuncExtension<in string, MyRefType, out Boolean>(string input, ref MyRefType refType);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23948 次 |
| 最近记录: |