C# Dictionary with dynamic type as Value
<p>Here's the thing, I don't know for sure which value I will add to my Dictionary, therefore I need the value field to be dynamic. The key is always a string though.</p>

<pre><code>Dictionary&lt;string, dynamic&gt; data = new Dictionary&lt;string, dynamic&gt;;
</code></pre>

<p>Now If I loop through my form controls I'm able to do the following:</p>

<pre><code>foreach (Control c in this.Controls)
{
   if(c is TextBox)
      data.Add(c.Name, c.Text);

   if(c is Checkbox)
      data.Add(c.Name, ((Checkbox)c).Checked);
}
</code></pre>

<p>I know that there's a key in my dictionary called <code>textBox1</code>, so how do I allow this kind of comparison?</p>

<pre><code>if(data["textBox1"] == "something")
</code></pre>

<p>I receive the error: </p>

<blockquote>
  <p>One or more types required to compile a dynamic expression cannot be
  found. Are you missing a reference?</p>
</blockquote>