zoukankan      html  css  js  c++  java
  • 接口的实现

    接口的实现分为隐式实现,显式实现和含有显式和隐式实现得到实现方式,下面将详细讲解这三种实现方式

    一.隐式实现

    interface MyInterface
     {
       void ImpMean();
     }
     public class ImpClass:MyInterface
    {
       public void ImpMean()
         {
           Console.WriteLine("接口的隐式实现");
         }


     } 

    class Program

     {
       static void Main(string[] args)
         {
          ImpClass impclass = new ImpClass();
           impclass.ImpMean();
           ((MyInterface)impclass).ImpMean();
           Console.ReadKey();
         }
    }

    控制台的最终显示为:

    接口的隐式实现

    接口的隐式实现

    二.显式实现

    interface Myterface
      {
         void Paint();
      }
    public class Emplicit:Myterface
      {
         void Myterface.Paint()
         {
           Console.WriteLine("接口的显式实现");
         }
      }
    class Program
     {
       static void Main(string[] args)
       {
           Emplicit emplicit = new Emplicit();
           ((Myterface)emplicit).Paint();
           Console.ReadKey();
       }
     }

    控制台的最终显示为:

    接口的显式实现

    三.同时含有显式和隐式实现

      interface MyInterface
        {
          void Write();
        }

      public class Synthesize : MyInterface
        {
          public void Write()
            {
              Console.WriteLine("接口的综合实现之一");
            }

          void MyInterface.Write()
            {
              Console.WriteLine("接口的综合实现之二");
            }

        }
      class Program
        {
          static void Main(string[] args)
          {
            Synthesize synthesize = new Synthesize();
            synthesize.Write();
            ((MyInterface)synthesize).Write();
            Console.ReadKey();
          }
        }

    控制台的最终显示为:

    接口的综合实现之一

    接口的综合实现之二

    注意:当同时有显式和隐式的实现时,显式实现才是真正的实现方法

  • 相关阅读:
    《Centos服务器版安装教程》
    从CentOS官网下载系统镜像详细教程
    一键LNMP文件
    Centos 7 ip地址
    cmd常用命令
    bat命令
    JAVA学习资源整理
    DevOps 高效 shell 命令
    编程范式:命令式编程(Imperative)、声明式编程(Declarative)和函数式编程(Functional)
    Java 中的函数式编程(Functional Programming):Lambda 初识
  • 原文地址:https://www.cnblogs.com/SancoLee/p/4575676.html
Copyright © 2011-2022 走看看