Dictionary<string, object> to Dictionary<string, float> : <p>I'm currently working on a .NET Framework 4.7.2 application. Given is a <code>Dictionary&lt;string, object&gt;</code>. I need to write a method to transform the structure to a <code>Dictionary&lt;string, float&gt;</code>.</p>

<pre><code>private List&lt;KeyValuePair&lt;int, Dictionary&lt;string, float&gt;&gt;&gt; CreateResult(List&lt;Dictionary&lt;string, object&gt;&gt; items)
{
    var result = new List&lt;KeyValuePair&lt;int, Dictionary&lt;string, float&gt;&gt;&gt;();

    for (int i = 0; i &lt; items.Count; i++)
    {
       var item = items[i].ToDictionary&lt;string, float&gt;(v =&gt; v); // Error, wrong approach
       result.Add(new KeyValuePair&lt;int, Dictionary&lt;string, float&gt;&gt;(i, new Dictionary&lt;string, float&gt;(item)));
    }
    return result;
}
</code></pre>

<p>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.</p>

<p>Do you know a good/save way to transform all values in my Dicitonary from type object to type float?</p>

<p>Thank you very much!</p>
