iterating by list formulating outline lines fly


edit: i missed essential point: .net 2.0



consider box where i have list unsorted items, effect probity form this:



class testclass
{
datetime sometime;
decimal someprice;

// constructor
}


i need emanate report-like output, where sum prices any accumulated. there should line any item, folled suitable outline lines.



take exam data:



list<testclass> testlist = new list<testclass> { 
new testclass(new datetime(2008,01,01), 12),
new testclass(new datetime(2007,01,01), 20),
new testclass(new datetime(2008,01,01), 18)
};


the preferred cost something this:



2007-01-01: 
20
total: 20

2008-01-01:
12
18
total: 30


what's best proceed approach such scenarios? box such list, i exercise icomparable interface testclass, list sorted.



to emanate news itself, something used (let's assume have methods tasks accumulating prices, retaining lane tide date etc):



for (int i=0;i<testlist.count;i++)
{
(isnewdate(testlist[i]))
{
createsummaryline();
resetvaluesfornewdate();
}

addvalues(testlist[i]);
}

// final outline line indispensable consolidate information final integrate items.
createsummaryline();


this works alright, nonetheless i have uncanny feeling distant second "createsummarylines" concerned.



in ways hoop such situations (especially deliberation fact, need work list<> equipment rather pre-categorized collection something that)?



Comments

Popular posts from this blog

list macos calm editors formula editors

how hibernate @any-related annotations?

using mvc, should hoop communication between views? between models?