KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have seen similar questions to this, but they involve different types so I think this is a new question. Consider the following code: public void Test(bool value) { // The following line provokes a compiler error: // "Type of conditional expression cannot be determined because there is // no implicit conversion between 'method group' and 'method group". Func<bool> test = value ? F : F; } public bool F() { return false; } Now, according to the C# 3.0 Standard, The second and third operands of the ?: operator control the type of the conditional expression. Let X and Y be the types of the second and third operands. Then, If X and Y are the same type, then this is the type of the conditional Otherwise, if an implicit conversion (§6.1) exists from X to Y, but not from Y to X, then Y is the type of the conditional expression. Otherwise, if an implicit conversion (§6.1) exists from Y to X, but not from X to Y, then X is the type of the conditional expression. Otherwise, no expression type can be determined, and a compile-time error occurs. It seems to me that in my sample code, X and Y must be of the same type, since they are the selfsame entity, Func . So why does it not compile?
Tags (comma-separated)
Save Edits
Cancel