如何实现接口数组化 输出有共同爱好的宠物

来源:2-8 结构和类

慕粉1550527049

2017-10-17 20:41

59e5fa810001d93d10010751.jpg59e5fa800001620b10010751.jpg

59e5fa810001207910010751.jpg
59e5fa81000177e710010751.jpg

写回答 关注

1回答

  • 慕粉3655233
    2017-10-18 17:03:02
    已采纳

     Interface1[] intt = new Interface1[] { new Dog("dddddd") };
                for (int i = 0; i < intt.Length; i++)
                {
                    intt[i].GGG();
                }

     interface Interface1
        {
            void GGG();
        }

     class Dog : Pet,Interface1

    {

     public void GGG()
            {
                Console.WriteLine("爬树");
            }

    }

     Interface1[] intt = new Interface1[] { new Dog("dddddd") };
                for (int i = 0; i < intt.Length; i++)
                {
                    intt[i].GGG();
                }

    //img4.sycdn.imooc.com/59e718c2000150b003330072.jpg

C#面向对象编程

本系列教程主要是,带你学习C#面向对象编程的编程思想、编程技巧

68599 学习 · 153 问题

查看课程

相似问题