我有点问题。我正在将数字添加到ArrayList
156、340(当它是TransferIn
或Buy
)等,然后我删除它们像 156、340(当它是TransferOut
,Sell
)一样。以下解决方案可以毫无问题地解决这个问题。我遇到的问题是,对于一些旧数据,员工输入的总和是 1500 而不是 500+400+100+500。我将如何更改它,以便当有 Sell/TransferOut 并且 ArrayList 内部没有匹配项时,它应该尝试从该 ArrayList 添加多个项目并找到组合成聚合的元素。
ArrayList alNew = new ArrayList();
ArrayList alNewPoIle = new ArrayList();
ArrayList alNewCo = new ArrayList();
string tempAkcjeCzynnosc = (string) alInstrumentCzynnoscBezNumerow[i];
string tempAkcjeInId = (string) alInstrumentNazwaBezNumerow[i];
decimal varAkcjeCena = (decimal) alInstrumentCenaBezNumerow[i];
decimal varAkcjeIlosc = (decimal) alInstrumentIloscBezNumerow[i];
int index;
switch (tempAkcjeCzynnosc) {
case "Sell":
case "TransferOut":
index = alNew.IndexOf(varAkcjeIlosc);
if (index != -1) {
alNew.RemoveAt(index);
alNewPoIle.RemoveAt(index);
alNewCo.RemoveAt(index);
} else {
// Number without match encountred
}
break;
case "Buy":
case "TransferIn":
alNew.Add(varAkcjeIlosc);
alNewPoIle.Add(varAkcjeCena);
alNewCo.Add(tempAkcjeInId);
break;
}
}