考虑以下代码:
if (xPoint > 0 && yPoint > 0) {
m_navigations = Directions.SouthEast;
}
else if (xPoint > 0 && yPoint < 0) {
m_navigations = Directions.NorthEast;
}
else if (xPoint < 0 && yPoint > 0) {
m_navigations = Directions.SouthWest;
}
else if (xPoint < 0 && yPoint < 0) {
m_navigations = Directions.NorthWest;
}
else if (xPoint == 0 && yPoint < 0) {
m_navigations = Directions.North;
}
else if (xPoint == 0 && yPoint > 0) {
m_navigations = Directions.South;
}
else if (xPoint > 0 && yPoint == 0) {
m_navigations = Directions.East;
}
else if (xPoint < 0 && yPoint == 0) {
m_navigations = Directions.West;
}
这很难看,我想使用 switch case,但是如何使用switch
变量2
?
我想过这样的事情- @Frits van Campen 的答案,但我需要使用>
和<
运营商......
谢谢