【发布时间】:2015-08-19 08:41:27
【问题描述】:
我在运行下面的代码 sn-p 时遇到问题,它给了我错误:
运算符'||'不能应用于'string'和'bool'类型的操作数
var qisg = new QuoteItemSectionGroup
{
SectionGroup = db.SectionGroups.Where(x => x.Name == "Ali Bottom Rail" && x.Section == TruckSection.FrontEndRequirments).First(),
StockItem = quoteItem.BodyType.Name == "Royal Corrugated" ? db.StockItems.Where(x => x.StockCode == "AEX165").First() : null,
};
qisg.Quantity = qisg.StockItem == null ? 0 : 1;
//Error in the line below
qisg.Length = qisg.StockItem == null ? 0 : (double)quoteItem.ExternalWidth + quoteItem.BodyType.Name = "Royal Corrugated" || quoteItem.BodyType.Name == "Royal Smooth Glued" || quoteItem.BodyType.Name == "Smooth Folded" || quoteItem.BodyType.Name == "Royal Smooth Riveted" ? -0.136 : -0.020;
quoteItem.SectionGroups.Add(qisg);
与使用 '||' 运算符不同的编码,我如何能够做相同类型的事情?
【问题讨论】:
-
在条件周围放置大括号
(...) -
某事运算符优先级。你试过搜索吗?
-
看来你的意思是
quoteItem.BodyType.Name == "Royal Corrugated"不只是"Royal Corrugated" -
@Dmitry Bychenko 是的,感谢您指出我的简单愚蠢错误! :D
-
感谢投反对票的人:(