I have a dictionary in C#:
public Dictionary<Product, int>
And I would like to get my result in to a generic list:
List<Product> productList = new List<Product>();
With the products orderder descending by the int value in the dictionary. I've tried using the orderby method, but without success.
You can do that using:
List<Product> productList = dictionary.OrderByDescending(kp => kp.Value)
.Select(kp => kp.Key)
.ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With