I am having this strange conditional expression problem when setting the value of Action<T> . It is not that I do not know how to get around this, as it is quite easy to solve using the usual if .
Here is my problem:
public class Test { public bool Foo { get; set; } public Action<bool> Action { get; set; } public void A() { Action = Foo ? B : C;
This gives me a compiler error with a message
There is no implicit conversion between a “method group” and a “method group”.
Which is strange, since I cannot understand why this would be illegal.
By the way, the syntax below will make this valid (from the point of view of compilers):
public void A() { Action = Foo ? (Action<bool>) B : C; }
So maybe you can read the question, how, why is casting necessary?
compiler-construction generics c # delegates
thekip
source share