-1

I am having some difficulties to convert a dictionary into a list.

var dic = new Dictionary<string, List<Tuple<DateTime, double>>>();
var list = new List<Tuple<DateTime, double>>();
list = dic.ToList(); // Cannot convert...
Martin G
  • 17,357
  • 9
  • 82
  • 98
Doro
  • 671
  • 1
  • 16
  • 34
  • 7
    `dic.Values.ToList()` – leppie Dec 17 '14 at 07:55
  • A dictionary is a key-value pair collection, a list is a collection of single elements. What do you expect the resultant list to look like? – Tim Dec 17 '14 at 07:55
  • Actually, I've just realised you have a more fundamental issue in that you have a List within the Dictionary. What is it you're actually trying to achieve? It you call ToLIst on the values the result will have to be List>> – DoctorMick Dec 17 '14 at 07:57
  • 1
    This is also a duplicate (a better one, actually): **[How to get dictionary values as a generic list](http://stackoverflow.com/questions/7555690/how-to-get-dictionary-values-as-a-generic-list)** – Kobi Dec 17 '14 at 07:59
  • @Tim I need to get the list part, dateTime and double. – Doro Dec 17 '14 at 09:11
  • @DoctorMick I am trying to get the list part = the values and not the keys. – Doro Dec 17 '14 at 09:12

1 Answers1

3

dict.ToList() will return collection of KeyValuePair<string, List<Tuple<DateTime, double>>().

If you want to hold all value's collection items in inside one list (flatten values) you need SelectMany:

list = dict.SelectMany(pair => pair.Value).ToList();