title: C# How to initialize a value (==null) inside an extension function?
body: <p>I have an extension function like  </p>
  
  <pre><code>public static bool AddDict(this Dictionary&lt;string, object&gt; obj, Dictionary&lt;string, object&gt; to_Add) 
    {to_Add.ToList().ForEach(x =&gt; obj.Add(x.Key, x.Value));}
  </code></pre>
  
  <p>and want to build up the resulting dictionary if someone will use it like </p>
  
  <pre><code>Dictionary&lt;string, object&gt; test=null;
  test.AddDict(oldDictionary);
  </code></pre>
  
  <p>I already tried</p>
  
  <pre><code>if (obj == null)
             obj = new Dictionary&lt;string, object&gt;();
  to_Add.ToList().ForEach(x =&gt; obj.Add(x.Key, x.Value));
  </code></pre>
  
  <p>as well as </p>
  
  <pre><code>if (obj == null)
        obj = (Dictionary&lt;string,object&gt;)to_add;
  else
        to_Add.ToList().ForEach(x =&gt; obj.Add(x.Key, x.Value));
  </code></pre>
  
  <p>But none of the above worked as intended. In booth ways the test-Dictionary seems to be null. Is there a way to initialize the this-value inside the function if it is null?</p>