private void btnPunto1_Click(object sender, EventArgs e) { try { Animal a01 = new Humano("Juan", DateTime.Now.AddYears(-10), Humano.Ocupacion.Infante); this.animales.Push(a01); Animal a02 = new Pez("Dory", Pez.PrincipalAlimento.Plancton); this.animales.Push(a02); Humano a03 = new Humano("Pedro", DateTime.Now.AddYears(1), Humano.Ocupacion.Infante); this.animales.Push(a03); Pez a04 = new Pez("Nemo", Pez.PrincipalAlimento.Otra); this.animales.Push(a04); Pez a05 = new Pez("Bruce", Pez.PrincipalAlimento.Carne); this.animales.Push(a04); } catch (FechaNacimientoInvalidaException ex) { MessageBox.Show(ex.Message); } // Variable para acumular los datos de la pila string datos = ""; // Vaciar la pila y mostrar su contenido en un solo String formado con StringBuilder foreach (Animal a in this.animales) { datos += a.ToString() + "\n"; } // Se muestran los datos MessageBox.Show(datos); }
public void TestXml() { //Arrange Pez nemo = new Pez("Nemo", Pez.PrincipalAlimento.Plancton); //Act nemo.Guardar("Pez.xml", nemo); Pez aux = nemo.Leer("Pez.xml"); //Assert Assert.IsTrue(nemo == aux); }
public static void Main(string[] args) { Animal perro = new Perro("Toby"); perro.caminar(); Animal pez = new Pez("Nemo"); pez.caminar(); Animal ave = new Ave("Condorito"); ave.caminar(); Console.ReadKey(); }
static void Main(string[] args) { Animal labrador = new Mamifero(); labrador.NombreCientifico = "Topo"; labrador.EdadPromedio = 5; Animal nemo = new Pez(); nemo.NombreCientifico = "Batman"; nemo.EdadPromedio = 5; Console.WriteLine(labrador.comer()); Console.WriteLine(labrador.comer(true)); Console.WriteLine(labrador.comer(false)); Console.WriteLine(labrador.comer(nemo)); Console.WriteLine(labrador.comer()); Console.WriteLine(nemo.comer()); Console.ReadKey(); }
//Guardar un Humano y un Pez en el escritorio con los nombres de archivo “Humano.bin” y “Pez.xml” respectivamente. private void btnPunto3_Click(object sender, EventArgs e) { Pez nemo = new Pez("Nemo", Pez.PrincipalAlimento.Plancton); Humano Seba = new Humano("Seba", DateTime.Now.AddYears(-29), Humano.Ocupacion.Estudiante); try { nemo.Guardar("Pez.xml", nemo); MessageBox.Show("Se serializo el pez"); MessageBox.Show("Leyendo pez..."); Pez aux = nemo.Leer("Pez.xml"); MessageBox.Show(aux.ToString()); Seba.Guardar("Humano.bin", Seba); MessageBox.Show("Se serializo el humano"); MessageBox.Show("Leyendo humano..."); Humano aux2 = Seba.Leer("Humano.bin"); MessageBox.Show(aux2.ToString()); } catch (Exception ex) { MessageBox.Show(ex.Message); } }