【发布时间】:2014-12-09 17:52:42
【问题描述】:
当分支选择一个函数时,使用三元运算符来选择一个函数可能是有意义的,但这是不可能的。为什么?
public class Demo {
protected bool branch;
protected void demo1 () {}
protected void demo2 () {}
public Action DoesntWork() {
return branch ? demo1 : demo2;
}
}
编译器产生以下错误:
Cannot implicitly convert type `method group' to `System.Action'
【问题讨论】:
标签: c# delegates ternary-operator