title: Passing List<int> by ref
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/729526/passing-in-object-by-ref">passing in object by ref</a>  </p>
  </blockquote>
  
  
  
  <p>With the code below, the output would be: </p>
  
  <pre><code>Without:
  With:1
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>    static void Main(string[] args)
      {
          var listWithoutRef = new List&lt;int&gt;();
          WithoutRef(listWithoutRef);
          Console.WriteLine("Without:" + string.Join(" ", listWithoutRef));
  
          var listWithRef = new List&lt;int&gt;();
          WithRef(ref listWithRef);
          Console.WriteLine("With:" + string.Join(" ", listWithRef));
      }
  
      static void WithoutRef(List&lt;int&gt; inList)
      {
          inList = new List&lt;int&gt;(new int[] { 1 });
      }
  
      static void WithRef(ref List&lt;int&gt; inList)
      {
          inList = new List&lt;int&gt;(new int[] { 1 });
      }
  </code></pre>
  
  <p>By just looking at this, I would have said that a List is on the Heap, and so is passed by ref anyway, so they should be the same? Am I misunderstanding the ref keyword? Or am I missing something else?</p>