Advertisement
hibbzboi

dict sorting method

May 10th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. Dictionary<int, double> SortowanieSlownika(Dictionary<int, double> slownik)
  2. {
  3. Dictionary<int, double> sortowany = slownik;
  4.  
  5. List<KeyValuePair<int, double>> tempList = new List<KeyValuePair<int, double>>(sortowany);
  6.  
  7. tempList.Sort(delegate (KeyValuePair<int, double> firstPair, KeyValuePair<int, double> secondPair)
  8. {
  9. return firstPair.Value.CompareTo(secondPair.Value);
  10. }
  11. );
  12.  
  13. tempList.Reverse();
  14.  
  15. Dictionary<int, double> posortowany = new Dictionary<int, double>();
  16. foreach (KeyValuePair<int, double> pair in tempList)
  17. {
  18. posortowany.Add(pair.Key, pair.Value);
  19. }
  20.  
  21. return posortowany;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement