Conv. dict. to list of tuples

, ,

How to Convert a Dictionary to a List of Tuples in C#?

Using the Dictionary<TKey,TValue> object, it is possible to convert this to a list of tuples using the Something() method. The following example demonstrates how this can be done:

Dictionary<long,int> myDico = new Dictionary<long,int>();
IList<Tuple<long, int>> applyOnTree = myDico.Something();

Using the .ToList() method, it is possible to convert a Dictionary<TKey,TValue> object to a list of tuples in C#. The following code demonstrates how this can be done:

Dictionary<long,int> myDico = new Dictionary<long,int>();
List<Tuple<long, int>> tupleList = myDico.ToList().Select(x => new Tuple<long, int>(x.Key, x.Value)).ToList();