Оптимизировать код (использовать цикл) - C#
Формулировка задачи:
int bitRESET;
int bitCE;
int bitOE;
int bitWE;
int bitBE;
int bitRDY;
.....................
{
if (sigName == "RESET")
bitRESET = ExtractBit(netList, elements[0], "=>", newlist, newlist.BackColor);
if (bitRESET == -1) return null;
if (sigName == "RDY")
bitRDY = ExtractBit(netList, elements[0], "<=", newlist, Color.LightGray);
if (bitRDY == -1) return null;
if (sigName == "CE")
bitCE = ExtractBit(netList, elements[0], "=>", newlist, newlist.BackColor);
if (bitCE == -1) return null;
if (sigName == "OE")
bitOE = ExtractBit(netList, elements[0], "=>", newlist, newlist.BackColor);
if (bitOE == -1) return null;
if (sigName == "WE")
bitWE = ExtractBit(netList, elements[0], "=>", newlist, newlist.BackColor);
if (bitWE == -1) return null;
if (sigName == "BE")
bitBE = ExtractBit(netList, elements[0], "=>", newlist, newlist.BackColor);
if (bitBE == -1) return null;
}Решение задачи: «Оптимизировать код (использовать цикл)»
textual
Листинг программы
int bitResult = -1;
switch (sigName)
{
case "RDY": bitResult = ExtractBit(netList, elements[0], "<=", newlist, Color.LightGray); break;
case "RESET":
case "CE":
case "OE":
case "WE":
case "BE": bitResult = ExtractBit(netList, elements[0], "=>", newlist, newlist.BackColor); break;
default: break;
}
if (bitResult == -1)
return null;