我有if或语句,其中放置了一些条件和三元运算符。我注意到,如果我输入?:运算符,则我的if语句始终为false。我想知道是什么原因造成的,因为真正的条件是在评估?:运算符之前出现的,因此它甚至不应该检查它。
row.number == barcode -> false;
row.eancode == barcode -> true;
row.packageean == barcode -> false;
row.IspackingcodeNull() -> true;
if (row.number == barcode
|| row.eancode == barcode
|| row.packageean == barcode
|| row.IspackingcodeNull() ? false : row.packingcode == barcode
|| row.producerproductcode == barcode
|| row.alternativebarcode1 == barcode)
答案 0 :(得分:4)
您实际上所做的是:
if
(
(
row.number == barcode
|| row.eancode == barcode
|| row.packageean == barcode
|| row.IspackingcodeNull()
)
? false
: row.packingcode == barcode || row.producerproductcode == barcode || row.alternativebarcode1 == barcode
)
您想要的是什么
if (row.number == barcode
|| row.eancode == barcode
|| row.packageean == barcode
|| (row.IspackingcodeNull() ? false : row.packingcode == barcode)
|| row.producerproductcode == barcode
|| row.alternativebarcode1 == barcode)