title: Why is my inheritance not working? The children objects deleted my ToString() method. C#
body: <p>I have 3 classes, the first one is an Abstract Class called Equipos with a ToString() abstract method, the second one is called Camiones which overrides the ToString() and shows the attributes &quot;marca&quot; and &quot;dominio&quot;, the third one is called Gruas and is the children of the second one (Camiones), and it also has the ToString() method and uses override to add more data to it, including the one from the second class.</p>
  <p>Here's the class Camiones:</p>
  <pre><code>public class Camiones : Equipos
  {
      #region atributos
      protected string marca;
      protected string dominio;
      #endregion
  
      #region constructores
      public string Marca
      {
          get { return marca; }
          set
          {
              marca = value;
          }
      }
      public string Dominio
      {
          get { return dominio; }
          set
          {
              dominio = value;
          }
      }
      #endregion
  
      #region metodos 
      public override string ToString()
      {
          string cadena = &quot;Dominio Camion: &quot; + this.dominio + &quot;Marca Camion: &quot; + this.marca;
          return cadena;
      }
  }
  </code></pre>
  <p>And this is the children of Equipos, called Gruas:</p>
  <pre><code>public class Grua : Camiones
  {
      #region atributos
      protected int altura;
      protected int peso;
      protected double precioHora;
      #endregion
  
      #region constructores
      public int Altura
      {
          get { return altura; }
          set
          {
              altura = value;
          }
      }
      public int Peso
      {
          get { return peso; }
          set
          {
              peso = value;
          }
      }
      public double PrecioHora
      {
          get { return precioHora; }
          set
          {
              precioHora = value;
          }
      }
      public override string ToString()
      {
          string cadena = base.ToString();
          cadena += &quot; - Peso Grua: &quot; + peso + &quot; Altura Grua: &quot; + altura + &quot; Precio Hora: &quot; + precioHora + &quot; Marca Grua: &quot; + this.marca;
          return cadena;
      }
  </code></pre>
  <p>I've done a MessageBox to show if the class Camiones is using the ToString() fine, and it does work. But when i call it on my third class Gruas, the ToString() from Camiones only shows &quot;Dominio Camion: -<em>doesn't show the attribute dominio</em>- Marca Camion: &quot; -<em>shows the attribute marca i set for Gruas, but it should show the attribute marca i set for Camiones!</em>-</p>
  <p>It seems like my third class is deleting the attributes i set for it's parent Class Camiones... i dont know why is this happening</p>
  <p>This is how i set my properties on my main form:</p>
  <p>Camiones nuevoCamion;
  nuevoCamion = new Camiones();</p>
  <pre><code>Grua nuevaGrua;
  nuevaGrua = new Grua();
  
  nuevoCamion.Marca = Convert.ToString(cbCamionMarca.SelectedItem);
  nuevoCamion.Dominio = Convert.ToString(tCamionDominio.Text);
  
  MessageBox.Show(nuevoCamion.Marca + &quot; &quot; + nuevoCamion.Dominio); //it shows everything it should show
  MessageBox.Show(nuevoCamion.ToString()); //it also shows everything it should show
  
  nuevaGrua.Marca = Convert.ToString(cbGruaTipo.SelectedItem);
  nuevaGrua.Peso = Convert.ToInt32(mtPesoMaximo.Text.Trim());
  nuevaGrua.Altura = Convert.ToInt32(mtAlturaIzaje.Text.Trim());
  nuevaGrua.PrecioHora = Convert.ToDouble(mtPrecioGrua.Text);
  
  parListaGruas.Add(nuevaGrua);
  MessageBox.Show(parListaGruas[0].ToString()); //only shows Dominio Camion: with no data, and Camion Marca: with marca from Gruas. And it shows the rest of the Gruas.ToString() ok- This is where im having issues
  MessageBox.Show(nuevoCamion.ToString()); //i called my nuevoCamion again to check if the data was still there, and its still there.
  </code></pre>