这是我目前的 if 语句:
if (excel_getValue("A" + i) == "" &&
excel_getValue("A" + (i + 1)) == "" &&
excel_getValue("A" + (i + 2)) == "" &&
excel_getValue("A" + (i + 3)) == "" &&
excel_getValue("A" + (i + 4)) == "" &&
excel_getValue("A" + (i + 5)) == "" &&
excel_getValue("A" + (i + 6)) == "" &&
excel_getValue("A" + (i + 7)) == "" &&
excel_getValue("A" + (i + 8)) == "")
无论如何我可以减少这个声明吗?我应该在 for 循环中构建此 if 语句吗?
顺便说一句,这个 if 语句 if 已经在 forloop 中并且它使用 forloop 的 i
最佳答案
您可以使用全部
:
if(Enumerable.Range(0, 9).All(c => excel_getValue("A" + (i + c)) == "")) {
}
关于c# - 减少 if 语句本身,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30751478/