zoukankan      html  css  js  c++  java
  • C#中的接口

    接口的注意事项:
       1)接口是实现,抽象方法是继承
       2)实现接口的类中可以有普通方法
       3)定义接口使用关键字Internet
       4)实现接口无关键字
       5)一次可以实现多个接口

    示例代码:
        //接口1
       public interface IFly
        {
           void Fly();
        }


        //接口2
       public interface IRun
        {
           void Run();
        }

    //实现接口
       public class Plan:IFly,IRun
        {
           public void Fly()
           {
               Console.WriteLine("plan fly");
           }
           public void  Run() 
           {
               Console.WriteLine("RUN");
           }
           public void Eat()  //普通方法
           {
               Console.WriteLine("eat");
           }
        }

     //实现接口
       public class Brid:IFly
        {
           public void Fly()
           {
               Console.WriteLine("fly");
           }
        }

    测试类:

    static void Main(string[] args)
            {
                List<IFly> list = new List<IFly>()
                {
                    new Brid(),
                    new Plan()
                };
                foreach (IFly item in list)
                {
                    item.Fly();
                }
                Console.ReadKey();
            }

  • 相关阅读:
    ANSI C
    如何判断机器的endianness
    union的常见用法
    主流浏览器引擎
    用宏来求数组元素个数
    inode
    分区时"磁盘上没有足够的空间完成此操作"的解决方法
    删除OEM分区
    jquery加table布局 模仿实现FaceBook Dialog
    Container.DataItem使用
  • 原文地址:https://www.cnblogs.com/sujulin/p/7086874.html
Copyright © 2011-2022 走看看