C# Add elements to Dictionary with key as string and value as another Dictionary
<p><strong>Background:</strong>
I have a dictionary diskInfo with key as string and value as dictionary of type string, double. For each entry into the foreach loop, I calculate the disk space and store the result into spaceInfo dictionary. This is then passed on to be stored as the value for corresponding key in diskInfo dictionary.  </p>

<p><strong>Problem</strong>
Each time I clear existing entries in spaceInfo and readd the key value pairs before storing into diskInfo dictionary. At the end of the loop, diskInfo dictionary has keys stored in correctly, but count of values is 0 for all keys. I am new to using Dictionaries, so could you please help in explaining why this happens.</p>

<p>Thankyou </p>

<pre><code>Dictionary&lt;string, double&gt; spaceInfo = new Dictionary&lt;string, double&gt;();
Dictionary&lt;string, Dictionary&lt;string, double&gt;&gt; diskInfo = new Dictionary&lt;string, Dictionary&lt;string, double&gt;&gt;();
foreach (ManagementObject mo in queryCollection)
        {
            double size = Convert.ToDouble(mo["Size"]) / divisor;
            double free = Convert.ToDouble(mo["FreeSpace"]) / divisor;

            double percentFree = (free / size) * 100;

            spaceInfo.Add("size",size);
            spaceInfo.Add("freeSpace",free);
            spaceInfo.Add("percentFree",percentFree);

            diskInfo.Add(Convert.ToString(mo["Name"]),spaceInfo);

            spaceInfo.Clear();
        }
</code></pre>