title: List passed by ref - help me explain this behaviour
body: <p>Take a look at the following program:</p>
  
  <pre><code>class Test
  {
      List&lt;int&gt; myList = new List&lt;int&gt;();
  
      public void TestMethod()
      {
          myList.Add(100);
          myList.Add(50);
          myList.Add(10);
  
          ChangeList(myList);
  
          foreach (int i in myList)
          {
              Console.WriteLine(i);
          }
      }
  
      private void ChangeList(List&lt;int&gt; myList)
      {
          myList.Sort();
  
          List&lt;int&gt; myList2 = new List&lt;int&gt;();
          myList2.Add(3);
          myList2.Add(4);
  
          myList = myList2;
      }
  }
  </code></pre>
  
  <p>I assumed <code>myList</code> would have passed by <code>ref</code>, and the output would </p>
  
  <pre><code>3
  4
  </code></pre>
  
  <p>The list is indeed "passed by ref", but only the <code>sort</code> function takes effect. The following statement <code>myList = myList2;</code> has no effect.</p>
  
  <p>So the output is in fact:</p>
  
  <pre><code>10
  50
  100
  </code></pre>
  
  <p>Can you help me explain this behavior? If indeed <code>myList</code> is not <em>passed-by-ref</em> (as it appears from <code>myList = myList2</code> not taking effect), how does <code>myList.Sort()</code> take effect? </p>
  
  <p>I was assuming even that statement to not take effect and the output to be:</p>
  
  <pre><code>100
  50
  10
  </code></pre>