c# - How to get the maximum/minimum value from a SortedDictionary? -



c# - How to get the maximum/minimum value from a SortedDictionary? -

i have built sorteddictionary<int, flowlayoutpanel> panels prescribed. looping on dictionary

foreach (var key in panels.keys.tolist()) { flowlayoutpanel tallestpanel = panels[key]; }

to entry maximum key value. trying write loop continually applies operation until count of dictionary 0. within loop need maximum , minimum value dictionary on each iteration. have read on sorteddictionary msdn entry , looks need utilize linq accomplish this. true? how that? (i've never touched linq)

and bonus question can't find reply to, sorteddictionaries sort largest smallest value i.e. if int in <int, flowlayoutpanel> represented flowlayoutpanels.height, loop above continually give me tallest panel?

since keys sorted in panels.keys, minimum , maximum keys first , lastly items in panels.keys. don't need linq this:

var keys = panels.keys.tolist(); // manually-determined indexes var min = panels[keys[0]]; var max = panels[keys[keys.count - 1]];

although arguably, it's clearer if utilize it:

var keys = panels.keys.tolist(); // or linq var min = panels[keys.first()]; var max = panels[keys.last()];

if want these values within loop that's looping through panel.keys.tolist() , removing each item dictionary goes (which think you're describing), minimum current, , maximum last.

var keys = panels.keys.tolist(); var max = panels[keys.last()]; foreach (var key in keys) { var min = panels[key]; // stuff panels.remove(min); }

c# linq dictionary

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -