

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Sort list of dictionaries by values in C#
Firstly, let us create a dictionary −
var d = new Dictionary<string, int>(5);
Now add the key and value −
// add key and value d.Add("car", 25); d.Add("bus", 28); d.Add("motorbike", 17);
Use orderby to order by values −
var val = from ele in d orderby ele.Value ascending select ele;
We have set ascending above to sort the dictionary in ascending order. You can also use descending.
Display the values in ascending order −
foreach (KeyValuePair ele in val) { Console.WriteLine("{0} = {1}", ele.Key, ele.Value); }
- Related Questions & Answers
- How to sort a list of dictionaries by values of dictionaries in C#?
- Ways to sort list of dictionaries by values in Python
- Ways to sort list of dictionaries by values in Python Using itemgetter
- Ways to sort list of dictionaries by values in Python Using lambda function
- Python program to Sort a List of Dictionaries by the Sum of their Values
- Ways to sort list of dictionaries using values in python
- How do I sort a list of dictionaries by values of the dictionary in Python?
- Python - Filter dictionaries by values in Kth Key in list
- Python – Sort Dictionaries by Size
- Sort Python Dictionaries by Key or Value
- MongoDB Aggregate sum of values in a list of dictionaries for all documents?
- Flatten given list of dictionaries in Python
- Python | Sort the values of first list using second list
- Sort list of tuples by specific ordering in Python
- Sort Dictionary key and values List in Python
Advertisements