title: Unforseen Dictionary behavior
body: <p>I ran into some curious behavior when using <em>C#</em> <code>Dictionary&lt;TKey, TValue&gt;</code> class. 
  First a little introduction:</p>
  
  <p>I have a definition of a class called AVariable: </p>
  
  <pre><code>public class AVariable
  {
      public AType VarType { get; set; }
  
      public AObject Value { get; set; }
  
      public AVariable(AObject val, AType type)
      {
          VarType = type;
          Value = val;
      }
  }
  </code></pre>
  
  <p>The following class takes care of these variables when inserting them into a Dictionary</p>
  
  <pre><code>public class VariablePool
  {
      private readonly Dictionary&lt;string, AVariable&gt; _runtimeVariableMap;
  
      public VariablePool()
      {
          _runtimeVariableMap = new Dictionary&lt;string, AVariable&gt;();
      }
  
      public void AddNewVariable(string name, AVariable vrb)
      {
          _runtimeVariableMap[name] = vrb;
      }
  
      public void DebugDump(TextWriter tw) // Just a demo for here
      { ... prints out stuff about variable...  }
  } 
  </code></pre>
  
  <p>This is how I use the mentioned classes:</p>
  
  <pre><code>private static void Main(string[] args)
  {
      var varPool = new VariablePool();
      varPool.AddNewVariable("a", new AVariable(new ANumeric(120), AType.ANumeric));
      varPool.AddNewVariable("b", new AVariable(new ANumeric(130), AType.ANumeric));
      varPool.AddNewVariable("c", new AVariable(new AString("Hello"), AType.AString));
      varPool.AddNewVariable("d", new AVariable(new AString("World"), AType.AString));
      varPool.DebugDump(Console.Out);
      Console.Read();
  }
  </code></pre>
  
  <p>EDIT: The A[Type] hierarchy</p>
  
  <pre><code>public class AObject
  {
  }
  
  public class AString : AObject
  {
      private static string _rawStr;
  
      public AString(string str)
      {
          _rawStr = str;
      }
  
      public AString(AString str)
      {
          _rawStr = str.GetRawValue();
      }
  
      public string GetRawValue()
      {
          return _rawStr;
      }
  }
  
  public class ANumeric : AObject
  {
      private static double _rawVal;
  
      public ANumeric(double val)
      {
          _rawVal = val;
      }
  
      public ANumeric(ANumeric num)
      {
          _rawVal = num.GetRawValue();
      }
  
      public double GetRawValue()
      {
          return _rawVal;
      }
  }
  </code></pre>
  
  <p>What I expect to be the output of <code>DebugDump</code>:</p>
  
  <pre><code>Name: a
  Type: ANumeric
  Value: 120
  
  Name: b
  Type: ANumeric
  Value: 130
  
  
  Name: c
  Type: AString
  Value: Hello
  
  Name: d
  Type: AString
  Value: World
  </code></pre>
  
  <p>What actually happens:</p>
  
  <pre><code>Name: a
  Type: ANumeric
  Value: 130
  
  Name: b
  Type: ANumeric
  Value: 130
  
  Name: c
  Type: AString
  Value: World
  
  
  Name: d
  Type: AString
  Value: World
  </code></pre>
  
  <p>My question is simple: Why does that happen? Why is the last <code>Value</code> applied to <em>all</em> the variables of same type? </p>
  
  <p>Thank you for your time. </p>
  
  <p>EDIT:
  GetRawValue() returns a private member that is assigned in constructor. </p>