title: Using Derived Class In a Base Method
body: <p>I want to reuse code in my <code>BaseRecordProcessor</code> class as much as possible, but I am having trouble figuring out how to use derived classes within the base class.</p>
  
  <p>An example of what I am trying to do is below. </p>
  
  <pre><code>public class BaseRecordProcessor
  {
      public void ProcessRecord()
      {
          List&lt;BaseRecord&gt; records = GetRecordValues();
  
          foreach (BaseRecord record in records)
          {
              DoStuff(record);
          }
      }
  
      public virtual DoStuff (BaseRecord record)
      {
          // do stuff
      }
  }
  
  public class DerivedRecordProcessor : BaseRecordProcessor
  {
      public override DoStuff (DerivedRecordOne record)
      {
          // do stuff
      }
  }
  </code></pre>
  
  <p>Notice the <code>DoStuff</code> method in the <code>DerivedRecordProcessor</code> class will be passing a <code>DerivedRecordOne</code> class to the method while the virtual method in the <code>BaseRecordProcessor</code> class is passing in the <code>BaseRecord</code> class. Is there a way to do this?</p>
  
  <p>Here are the record classes:</p>
  
  <pre><code>public class BaseRecord
  {
      // hold record information
  }
  
  public class DerivedRecordOne : BaseRecord
  {
      // hold additional record information
  }
  
  public class DerivedRecordTwo : BaseRecord
  {
      // hold more record information
  }
  </code></pre>