title: Cannot implicitly convert type NewDerivedClass to DerivedClass
body: <p>I have existing code which has a Base class with some common properties and a derived class that has a few extra properties: Property1 &amp; Property2.</p>
  
  <p>I have the following function which populates some property details:</p>
  
  <pre><code>public void MyFunction(BaseClass base)
  { 
      var derivedClass = base as DerivedClass;
  
      derivedClass.Property1 = "blah";
      derivedClass.Property2 = "blahblah";
  }
  </code></pre>
  
  <p>Now I have another new class <strong>NewDerivedClass</strong> that is also derived from BaseClass and need to modify the existing code to cope with this.</p>
  
  <p>Ideally I would like to do something like this:</p>
  
  <pre><code>public void MyFunction(BaseClass base)
  { 
      var derivedClass = base as DerivedClass;
  
      if(SomeConditionTrue)
      {
          derivedClass = base as NewDerivedClass
      }
  
      derivedClass.Property1 = "blah";
      derivedClass.Property2 = "blahblah";
  }
  </code></pre>
  
  <p>But I get the error: <strong>Cannot implicitly convert type NewDerivedClass to DerivedClass.</strong></p>
  
  <p>Ideally I would use generics like suggested here: <a href="https://stackoverflow.com/questions/3757858/cannot-implicitly-convert-type-customtype-to-othercustomtype">Cannot implicitly convert type &#39;customtype&#39; to &#39;othercustomtype&#39;</a> but there are too many places that I would have to modify code if I change the existing DerivedClass to use an interface.</p>
  
  <p>Is there a way I can handle this converting to a different class if a condition is true.</p>