我在下面的大型if语句中引用了一系列要分配的数组。如果可能,我想以某种方式间接引用它们?
if (m == 1) EleN[CorrPos] = S1N[ID];
else if (m == 2) EleN[CorrPos] = S2N[ID];
else if (m == 3) EleN[CorrPos] = S3N[ID];
else if (m == 4) EleN[CorrPos] = S4N[ID];
else if (m == 5) EleN[CorrPos] = S5N[ID];
else if (m == 6) EleN[CorrPos] = S6N[ID];
else if (m == 7) EleN[CorrPos] = S7N[ID];
else if (m == 8) EleN[CorrPos] = S8N[ID];
else if (m == 9) EleN[CorrPos] = S9N[ID];
else if (m == 10) EleN[CorrPos] = S10N[ID];
是否可以像间接地那样间接地调用此方法?
EleN [CorrPos] = @“ S” + m +“ N [ID]”
最佳答案
您可以使用指向S
数组的指针数组,然后只需执行例如
EleN[CorrPos] = S_Array[m - 1][ID]; // -1 since array-indexes are zero-based