linq - C# sorting a List of Strings by a List of Doubles -


i need create list of strings represent top 5 of summed values.

i have database hundreds of bills pertaining different services

ex. electric $600 january 2013 water $50 january 2013

i need sum same services have done here

public list<double> getsumofsingleservices     {                 {              var sums = (from dc in getdashboarddata                                                     group dc dc.servicetype g                         select g.sum(sc => sc.servicecost)).tolist();              return sums;         }         set         {             notifypropertychanged("getsumofsingleservices");         }      } 

i created list of string following code below

public list<string> getservicenames     {                 {              var names = (from dc in getdashboarddata                          group dc dc.servicetype g                                                       select g.first().servicetype).tolist();              return names;         }         set         {             notifypropertychanged("getservicenames");         }     } 

now data in these 2 lists parallel meaning getsumofsingleservices[0] value getservicenames[0] , on.

i have list has strings ranked highest value getsumofsingleservices first , on.

so if highest getsumofsingleservices[3] , parallel string getservicenames[3], getservicenames[3] first entry in list.

not sure how sort through list of strings double values.

that

for general problem i'd use schwartzian transform, common schema used in perl. should easy port underlying method .net

your case simpler have full control of data access:

var tuples = dc in getdashboarddata             group dc dc.servicetype g             select new{                 cost = g.sum(sc=>sc.servicecost),                 type = g.key,             }; var sorted = tuples.orderbydescending(t=>t.cost).select(t=>t.type); return sorted.tolist(); 

Comments