Exemple #1
0
        static void SimpleLinq(List <Animal> animais)
        {
            Rato r = (Rato)(from a in animais where a.Nome == "Jerry" select a).First();

            r.BarulhoDeRato();
            Gato g = (Gato)(from a in animais where a.Nome == "Gatito" select a).FirstOrDefault();

            Console.WriteLine(g.Nome);
            Cachorro c = (Cachorro)(from a in animais where a.Nome == "Toto" select a).First();

            c.Latir();
            Elefante e = (Elefante)(from a in animais where a.Nome == "Pumba" select a).FirstOrDefault();
        }
Exemple #2
0
        static void SimpleImplicityCast()
        {
            Animal gato = new Gato("Milk");

            gato.Sexo = 'F';
            Console.WriteLine(gato.ToString());
            Animal cachorr = new Cachorro("Panthera");

            cachorr.Sexo = 'F';
            Console.WriteLine(cachorr.ToString());
            Animal el = new Elefante("Dumbo");

            el.Sexo = 'M';
            Console.WriteLine(el.ToString());
            Animal rato = new Rato("Jerry");

            Console.WriteLine(rato.ToString());
        }