爲什麼不編譯?以下代碼有什麼錯誤?爲什麼三元運算符不是這樣工作的?
(_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