title: Why list preserves the value of another null list in c#
body: <p>I was going through differences between Stack and Heap and tried something to understand the reference type and value type variables. What I understood is that a reference type holds the address of value stored in heap and if the value in heap is changed all the reference to that address will point to new value, so I played with below codes but I am wondering why the below code prints a value of <code>10</code> when <code>lt1</code> is set to <code>null</code>:</p>
  
  <pre><code>public void Method4()
  {
      List&lt;int&gt; lt1 = new List&lt;int&gt;() { 1, 2, 3, 4 };
      List&lt;int&gt; lt2 = lt1;
      lt1 = null;
      int xx = lt2.Sum();
      Console.WriteLine(xx);
  }
  </code></pre>
  
  <p>But it prints <code>0</code> when <code>lt1</code> is cleared.</p>
  
  <pre><code>public void Method4()
  {
      List&lt;int&gt; lt1 = new List&lt;int&gt;() { 1, 2, 3, 4 };
      List&lt;int&gt; lt2 = lt1;
      lt1.Clear();
      int xx = lt2.Sum();
      Console.WriteLine(xx);
  }
  </code></pre>
  
  <p>I think <code>lt2</code> holds the reference of <code>lt1</code> and when <code>lt1</code> is set to null then <code>lt2</code> should also be null but this is not the case.</p>
  
  <p>What is going on in the background?</p>