views:

118

answers:

1
public object MethodName(ref float y)
{
//method
}

How do I defined a Func delegate for this method?

+9  A: 

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);
}
Elisha
The reason being: all generic type arguments must be things that are convertible to object. "ref float" is not convertible to object, so you cannot use it as a generic type argument.
Eric Lippert
Thanks for that, I was struggling to use Func so I know why I cant use it when type is not convertible to object
chugh97