zoukankan      html  css  js  c++  java
  • 20-C#笔记-接口

    # 1 接口的使用示例

    使用interface,关键字

    接口的实现和使用,和继承类似。

    在使用之前,要实现接口。

    using System;
    
    interface IMyInterface
    {
        // 接口成员
        void MethodToImplement();
    }
    
    class InterfaceImplementer : IMyInterface
    {
        static void Main()
        {
            InterfaceImplementer iImp = new InterfaceImplementer();
            iImp.MethodToImplement();
        }
    
        public void MethodToImplement()
        {
            Console.WriteLine("MethodToImplement() called.");
        }
    }
    

      

    # 2 接口的继承

    在继承接口的类中,要实现所有的接口

    using System;
    
    interface IParentInterface
    {
        void ParentInterfaceMethod();
    }
    
    interface IMyInterface : IParentInterface
    {
        void MethodToImplement();
    }
    
    class InterfaceImplementer : IMyInterface
    {
        static void Main()
        {
            InterfaceImplementer iImp = new InterfaceImplementer();
            iImp.MethodToImplement();
            iImp.ParentInterfaceMethod();
        }
    
        public void MethodToImplement()
        {
            Console.WriteLine("MethodToImplement() called.");
        }
    
        public void ParentInterfaceMethod()
        {
            Console.WriteLine("ParentInterfaceMethod() called.");
        }
    }
    

      

    参考:

    http://www.runoob.com/csharp/csharp-interface.html

  • 相关阅读:
    Xcode And iOS9新特性
    AutoLayout
    本地化
    Map
    iOS多线程编程
    第三方抽屉效果
    iPad编程
    CoreData / MagicalRecord
    js清除单选框所选的值
    js获取背景颜色
  • 原文地址:https://www.cnblogs.com/alexYuin/p/9069538.html
Copyright © 2011-2022 走看看