public object MethodName(ref float y)
{
// elided
}
How do I define a Func
delegate for this method?
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);
in
and out
you're showing for paramerizing the delegate pertain to co- versus "contra-variance", and are not related to what the OP is asking about. The question was about delegates which can accept parameters by reference, not the agility of a (generic) delegate with regard to its type parameteriization. –
Redwine © 2022 - 2024 — McMap. All rights reserved.