質問
ちょっと問題があります。数字を追加しています ArrayList
156、340のような(それが TransferIn
または Buy
)など、それから私は156、340のようにそれを実行してそれらを削除します(それが TransferOut
, Sell
)。次の解決策は問題なく機能します。私が抱えている問題は、一部の古いデータについて、従業員が 500+400+100+500 ではなく 1500 のような合計を入力していたことです。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;
}
}
他のヒント
これはあなたが思っているよりも難しいことが判明する可能性があります。
所属していません StackOverflow