Counting problem C#
Posted
by MadBoy
on Stack Overflow
See other posts from Stack Overflow
or by MadBoy
Published on 2010-03-19T10:16:08Z
Indexed on
2010/03/19
10:21 UTC
Read the original article
Hit count: 285
Hello,
I've a bit of a problem. I'm adding numbers to ArrayList
like 156, 340 (when it is TransferIn
or Buy
) etc and then i remove them doing it like 156, 340 (when it's TransferOut
, Sell
). Following solution works for that without a problem. The problem I have is that for some old data employees were entering sum's like 1500 instead of 500+400+100+500. How would I change it so that when there's Sell/TransferOut and there's no match inside ArrayList it should try to add multiple items from that ArrayList and find elements that combine into aggregate.
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;
}
}
© Stack Overflow or respective owner