Reputation: 45
I have a Dictionary
which is filled with Lists
each list represents a Datacolumn
in my Datatable
. I am trying to iterate through a specific list in the dictionary but i get an error when trying to append i, stating I cannot convert from object to double.
Dictionary<string, Dictionary<string, List<object>>> dict;
I add to the dictionary by;
dict = dt.Columns.Cast<DataColumn>().ToDictionary(c => c.ColumnName, c => dt.AsEnumerable().Select(r => r[c]).ToList());
Where the error happens;
XyDataSeries<double,double> xyseries;
private void chkbx1_Checked(object sender, RoutedEventArgs e)
{
var list = dict["ColumnName1"];
foreach (var i in list)
{
Convert.ToDouble(i);
xyseries.Append(one++, i);
}
}
Upvotes: 0
Views: 106
Reputation: 32740
Your problem is here: Convert.ToDouble(i);
ToDouble
returns a double
, it doesn't change i
into a double. You need to do the following:
foreach (var i in list)
{
var d = Convert.ToDouble(i);
xyseries.Append(one++, d);
}
Upvotes: 4