This post will discuss how to convert a Dictionary<TKey,TValue> to a List<T> in C#.

The LINQ’s Select() method transforms each element of a sequence into a new form. The following code example demonstrates how we can use Select() to project over elements of a dictionary and get a list of its keys.

Download  Run Code

 
To get a list of its values, use Dictionary<TKey,TValue>.Values property instead. You can skip using the Select() method using the following snippet:

Download  Run Code

 
Alternatively, if you need a list of key-value pairs, you can directly invoke the ToList() method on your dictionary instance.

Download  Run Code

Output:

[A, 1], [B, 2], [C, 3], [D, 4], [E, 5]

That’s all about converting Dictionary<TKey,TValue> to a List<T> in C#.