title: How to pass List<DerivedClass> when param type is List<BaseClass>?
body: <p>How can i pass a list which is a list of DerivedObjects where the Method is expecting a list of BaseObjects. I am converting the list <code>.ToList&lt;BaseClass&gt;()</code> and am wondering if there is a better way. My second problem is the syntax is incorrect. I am trying to pass the list byref and i am getting an error: <code>'ref' argument is not classified as a variable</code></p>
  
  <p>How can I fix these two problem? thanks.</p>
  
  <pre><code>public class BaseClass { }
  public class DerivedClass : BaseClass { }
  
  class Program
  {
      static void Main(string[] args)
      {
          List&lt;DerivedClass&gt; myDerivedList = new List&lt;DerivedClass&gt;();
          PassList(ref myDerivedList.ToList&lt;BaseClass&gt;());
  // SYNTAX ERROR ABOVE IS - 'ref' argument is not classified as a variable
  
          Console.WriteLine(myDerivedList.Count);
      }
  
      public static void PassList(ref List&lt;BaseClass&gt; myList)
      {
          myList.Add(new DerivedClass());
          Console.WriteLine(myList.Count);
      }
  }
  </code></pre>
  
  <p><strong>Solved:</strong></p>
  
  <p>A method similar to this has solved my issue. </p>
  
  <pre><code>public static void PassList&lt;T&gt;(ref List&lt;T&gt; myList) where T : BaseClass
  {
      if (myList == null) myList = new List&lt;T&gt;(); 
      // sorry, i know i left this out of the above example.
  
      var x = Activator.CreateInstance(typeof(T), new object[] {}) as T;
      myList.Add(x);
      Console.WriteLine(myList.Count);
  }
  </code></pre>
  
  <p>Thank you to all who help across this question and from other SO questions.</p>