title: Dictionary with object as value
body: <p>I'm going nuts here. It's probably because I've missed some rule, but if so, then please tell me.</p>
  
  <p>I'm trying to create a <code>Dictionary</code> with a string for key and an anonymous object as value. Or, actually I'm not just trying, I'm doing it.
  But when I want to alter a specific parameter in the object, it goes wrong.</p>
  
  <p>I declare the dictionary like this:</p>
  
  <pre><code>var areas = new Dictionary&lt;string, object&gt;
  {
    {"Key1", new {name = "Name1", today = 0, all = 0}},
    {"Key2", new {name = "Name2", today = 0, all = 0}},
      ...
  }
  </code></pre>
  
  <p>And then I'm assuming I can do this:</p>
  
  <pre><code>foreach (var area in areas.Keys.ToArray())
  {
      var areaname = areas[area].name;
  }
  </code></pre>
  
  <p>but Visual Studio does not agree, and refuses to compile. If I write this, though, everything works as I would think - but that doesn't really help me out, it's just making me more frustrated.</p>
  
  <pre><code>var areaname = new 
              {
                   name = "Nametest", today = 0, all = 0
              };
  var testname = areaname.name;
  </code></pre>
  
  <p>What am I doing wrong? Why isn't it working for me? Is it simply impossible to do so?</p>
  
  <p><strong>Thanks for all your answers, they surely cleared things up a bit!
  I think I might have been confusing the type <em>object</em> with the idea of objects, that is classes, in C# out of frustration. I'll rethink the whole design business and probably do something completely different instead of using evil or dirty solutions. Though interesting, I don't think my relationship with C# has evolved that far yet!</strong></p>