public object MethodName(ref float y) { //method }
How do I defined a Func delegate for this method?
C# - Func Delegate Func is a generic delegate included in the System namespace. It has zero or more input parameters and one out parameter. The last parameter is considered as an out parameter.
Func is a generic delegate included in the System namespace. It has zero or more input parameters and one out parameter. The last parameter is considered as an out parameter. This delegate can point to a method that takes up to 16 Parameters and returns a value.
TResult. The type of the return value of the method that this delegate encapsulates. This type parameter is covariant. That is, you can use either the type you specified or any type that is more derived. For more information about covariance and contravariance, see Covariance and Contravariance in Generics.
The key here is using the += operator (not the = operator) and looping through the list that is retrieved by calling GetInvocationList() and then calling Invoke() on each delegate retrieved. Hope this helps!
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); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With