I want to define an implicit conversion from (specific) lambda expressions to a user-defined type. I tried the following:
public static implicit operator DualElement<T>(Func<OPTatom, OPTatom, T> atomMap)
{
return new DualElement<T>(e => atomMap(e[0],e[1]));
}
Then I tried
DualElement<double> dubidu = (i, j) => cost[i, j];
which gives "Cannot convert lambda expression ... because it is not a delegate type"
Instead, what works is:
DualElement<double> dideldu = (Func<OPTatom, OPTatom, double>)((i, j) => cost[i, j]);
I guess, lambda expressions do not have the type 'Func' so that I have to put something different into the implicit conversion.
Can somebody give me a hint?