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();
        }

原文地址:https://www.cnblogs.com/sujulin/p/7086874.html