title: C# inheritance. Derived class from Base class
body: <p>I have a base class</p>
  
  <pre><code>public class A   
  {
      public string s1;
      public string s2;
  }
  </code></pre>
  
  <p>I also have a derived class : </p>
  
  <pre><code>public class B : A
  {
      public string s3;
  }
  </code></pre>
  
  <p>Suppose my program created an instance of class A.</p>
  
  <pre><code>A aClassInstance = new A();
  </code></pre>
  
  <p>some parameters were set:</p>
  
  <pre><code>aClassInstance.s1 = "string 1";
  aClassInstance.s2 = "string 2";
  </code></pre>
  
  <p>At this point I would like to create an instance of class B. But I would like B to already have the values of my instance of class A.</p>
  
  <p>This DID NOT Work:</p>
  
  <pre><code>public B bClassInstance = new B():
  bClassInstance = (B)aClassInstance;
  </code></pre>
  
  <p>NEITHER DID THIS:</p>
  
  <p>Made a clone method within Class A.</p>
  
  <pre><code>public B cloneA() {    
      A a = new A();
      a = (A)this.MemberwiseClone()
      return(B)a;
  }
  </code></pre>
  
  <p>The VS code takes both of the above - but I get run-time errors</p>
  
  <p>Please help</p>