Func delegate with ref variable

chugh97 picture chugh97 · Mar 17, 2010 · Viewed 28.3k times · Source
public object MethodName(ref float y)
{
//method
}

How do I defined a Func delegate for this method?

Answer

Elisha picture Elisha · Mar 17, 2010

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);
}