Here you go.
If you like it, please mark answer accepted.
public void DoGroupBy()
{
int[] arrayOL = { 8, 8, 8, 9, 9 };
int[] arrayQty = { 20, 30, 40, 50, 100 };
int nRows = 5;
int ORDERLINK, QTY;
int oldOL = 0, SumQty = 0;
Dictionary<int,int> result = new Dictionary<int,int>();
for (int i = 0; i < nRows; ++i)
{
ORDERLINK = arrayOL[i];
QTY = arrayQty[i];
if (i > 0)
{
if (ORDERLINK == oldOL)
{
SumQty += QTY;
}
else
{
result.Add(oldOL, SumQty);
SumQty = QTY;
}
}
else
{
SumQty = QTY;
}
oldOL = ORDERLINK;
}
result.Add(oldOL, SumQty);
Console.WriteLine("ORDERLINK QTY");
Dictionary<int,int>.Enumerator en = result.GetEnumerator();
while (en.MoveNext())
{
Console.WriteLine(String.Format("{0} {1}", en.Current.Key,
en.Current.Value));
}
}