为什么不编译?以下代码有什么错误?为什么三元运算符不是这样工作的?
(_DbContext == null) ? return _DbContext = new ProductAndCategoryEntities() : return _DbContext;
如果我再说一遍而言,如果它编译:
if (_DbContext == null)
return _DbContext = new ProductAndCategoryEntities();
else return _DbContext;
'_DbContext =(_DbContext == null)?新的ProductAndCategoryEntities():_DbContext;'这工作? – 2013-04-18 05:21:16
@legendinmaking - 你是完全正确的这是很好的解决方案 – 2013-04-18 05:30:56
它是“条件”运营商btw;它发生在操作数的数量方面* be *三元组... – 2013-04-18 06:23:21