提前道歉,不要赛马我的马匹'
Haven在任何地方都没有看到这个确切的问题,但只是好奇什么类型的if语句会更有效,或者它是否可以忽略不计,而且只是基于编译器。
if (data[i].Occupied) {
var color1 = "#E51616";
var drop1 = "";
var drag1 = "LocationDrag";
var work1 = data[i].Works_Order_Number;
} else {
var color1 = "#008000";
var drop1 = "tdDrop";
var drag1 = "";
var work1 = "";
}
if (data[i + 1].Occupied) {
var color1 = "#E51616";
var drop1 = "";
var drag1 = "LocationDrag";
var work1 = data[i].Works_Order_Number;
} else {
var color1 = "#008000";
var drop1 = "tdDrop";
var drag1 = "";
var work1 = "";
}
OR
var color1 = data[i].Occupied ? "#E51616" : "#008000";
var color2 = data[i + 1].Occupied ? "#E51616" : "#008000";
var drop1 = data[i].Occupied ? "" : "tdDrop";
var drop2 = data[i + 1].Occupied ? "" : "tdDrop";
var drag1 = data[i].Occupied ? "LocationDrag" : "";
var drag2 = data[i].Occupied ? "LocationDrag" : "";
var work1 = data[i].Occupied ? data[i].Works_Order_Number : "";
var work2 = data[i + 1].Occupied ? data[i + 1].Works_Order_Number : "";
答案 0 :(得分:3)
为什么不测试自己?只需在System Diagnostics命名空间中使用Stopwatch类,看看是否可以找到执行时间的任何差异。
然而,我会非常自信地说你不会发现差异,或者它会如此之小,无关紧要。正如其他人所说,可读性在这里获胜。