title: Convert base class to derived class
body: <p>Is it possible in C# to explicitly convert a base class object to one of it's derived classes? Currently thinking I have to create a constructor for my derived classes that accept a base class object as a parameter and copy over the property values. I don't really like this idea, so I'd like to avoid it if possible.</p>
  
  <p>This doesn't seem like it should work (object is instantiated as new base, so memory shouldn't be allocated for extra members of the derived class) but C# seems to allow me to do it:</p>
  
  <pre><code>class BaseClass
  {
    ... some stuff ...
  }
  
  class DerivedClass : BaseClass
  {
      public bool MyDerivedProperty{ get; set; }
  }
  
  
  static void Main(string[] args)
  {
      BaseClass myBaseObject = new BaseClass();
      DerivedClass myDerivedObject = myBaseObject as DerivedClass;
  
      myDerivedObject.MyDerivedProperty = true;
  }
  </code></pre>