Esempio n. 1
0
        static void TestOutInterfaces()
        {
            // This exhibits polymorphism because
            // we are able to group together types
            ISpeak[] speaks = new ISpeak[2];

            ISpeak speak = new Smurf();

            // unicorn implements ispeak...so we can use it
            Unicorn uni = new Unicorn();

            uni.Color = "pink";
            uni.Name  = "Magical Unicorn";
            uni.CreateCutieMark();

            Smurf smurf = new Smurf();

            smurf.Name = "Smurfy";

            speaks[0] = uni;
            speaks[1] = smurf;

            for (int i = 0; i < speaks.Length; i++)
            {
                speaks[i].SayHello();
            }

            MagicalCreature[] mc = new MagicalCreature[2];

            Dragon dragon = new Dragon();

            mc[0] = uni;
            mc[1] = dragon;

            for (int i = 0; i < mc.Length; i++)
            {
                if (mc[i] is ISpeak)
                {
                    // put that obj in another array
                    // save it into the db
                }
            }
        }