
- 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
How to sort a list of dictionaries by values of dictionaries in C#?
Set the list of dictionaries with keys and values.
var d = new Dictionary<string, int>(); d.Add("Zack", 0); d.Add("Akon", 3); d.Add("Jack", 2); d.Add("Tom", 1);
Get and sort the keys.
var val = d.Keys.ToList(); val.Sort();
You can try to run the following code to sort a list of dictionaries by values.
Example
using System; using System.Collections.Generic; using System.Linq; class Demo { static void Main() { var d = new Dictionary<string, int>(); d.Add("Zack", 0); d.Add("Akon", 3); d.Add("Jack", 2); d.Add("Tom", 1); // Acquire keys and sort them. var val = d.Keys.ToList(); val.Sort(); // Loop through keys. foreach (var key in val) { Console.WriteLine("{0}: {1}", key, d[key]); } } }
Output
Akon: 3 Jack: 2 Tom: 1 Zack: 0
- Related Articles
- Sort list of dictionaries by values 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 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
- Ways to sort list of dictionaries by values in Python Using lambda function
- Python – Sort Dictionaries by Size
- Python - Filter dictionaries by values in Kth Key in list
- Sort Python Dictionaries by Key or Value
- MongoDB Aggregate sum of values in a list of dictionaries for all documents?
- How to create a pandas DataFrame using a list of dictionaries?
- Flatten given list of dictionaries in Python
- Append list of dictionaries to an existing Pandas DataFrame in Python
- Python – Remove Dictionaries with Matching Values

Advertisements