What's the easiest way to reorder two dictionary lists together in C#? -


background problem

say had following 2 lists (priosums , contentvals) compiled sql server ce query this:

var queryresults = db.query(searchquerystring, searchtermsarray);  dictionary<string, double> priosums = new dictionary<string, double>(); dictionary<string, string> contentvals = new dictionary<string, string>(); double priotemp = 0.0; foreach(var row in queryresults) {     string location = row.location;     double priority = row.priority;      if (!priosums.containskey(location))     {         priosums[location] = 0.0;     }      if (!contentvals.containskey(location))     {         contentvals[location] = row.value;         priotemp = priority;     }      if (priotemp < priority)     {         contentvals[location] = row.value;     }      priosums[location] += priority; } 

the query pretty large, dynamically compiled, , beyond scope of question, i'll returns rows include priority, text value, , location.

with above code able 1 list (priosums) sums of priorities each location (not allowing repeats on location [key] itself, though repeats location in query results), , list (contentvals) hold value of location highest priority, once again, using location key.

all of have accomplished , works well. can iterate on 2 lists , display information want however...

the problem

...now need reorder these lists highest priority (or sums of priorities stored values in priosums) first.

i have wracked brain trying think using instantiated class 3 properties given advice others, can't seem wrap brain on how work, given webmatrix c#.net-webpages environment. know how call class .cs file current .cshtml file, no problem, have never done instantiating class make object before (sorry, still new of more complex c# logic/methodology).

can suggest how accomplish this, or perhaps show easier (at least easier understand) way of doing this? in short need these 2 lists ordered value in priosums highest lowest.

note

please forgive me if have not provided quite enough information. if more should provided don't hesitate ask.

also, more information or background on problem, can @ previous question on here: is there way loop through sql results , store name/value pairs elsewhere in c#?

i dont know if outcome want can give try:

var result = p in priosums           orderby p.value descending           select new { location = p.key, priority = p.value, value = contentvals[p.key] }; 

Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -