I'm currently working on a .NET Framework 4.7.2 application. Given is a Dictionary<string, object>
. I need to write a method to transform the structure to a Dictionary<string, float>
.
private List<KeyValuePair<int, Dictionary<string, float>>> CreateResult(List<Dictionary<string, object>> items)
{
var result = new List<KeyValuePair<int, Dictionary<string, float>>>();
for (int i = 0; i < items.Count; i++)
{
var item = items[i].ToDictionary<string, float>(v => v); // Error, wrong approach
result.Add(new KeyValuePair<int, Dictionary<string, float>>(i, new Dictionary<string, float>(item)));
}
return result;
}
Unfortunately my method does not work, neither I don't really know if it's the right approach to transform all values of my dictionary to type float.
Do you know a good/save way to transform all values in my Dicitonary from type object to type float?
Thank you very much!