
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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 Articles
- 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
- 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 program to Sort a List of Dictionaries by the Sum of their Values
- Python - Filter dictionaries by values in Kth Key in list
- Python – Sort Dictionaries by Size
- Sort Python Dictionaries by Key or Value
- How can I sort one list by values from another list in Python?
- MongoDB Aggregate sum of values in a list of dictionaries for all documents?
- Python | Sort the values of first list using second list
- Flatten given list of dictionaries in Python
- Sort Dictionary key and values List in Python

Advertisements