• C# -- 接口 (关键字:interface)


    C#: 接口(关键字:interface)

    1.代码(入门举例)

     1     class Program
     2     {
     3         static void Main(string[] args)
     4         {
     5             Console.WriteLine("-------------------------------------");
     6             IIntroduce iSE = new SoftwareEngineer();
     7             iSE.SayHi();
     8             iSE.DescribeMyself();
     9             iSE.SayGoodbye();
    10 
    11 
    12             Console.WriteLine("-------------------------------------");
    13             IIntroduce iTc = new Teacher();
    14             iTc.SayHi();
    15             iTc.DescribeMyself();
    16             iTc.SayGoodbye();
    17 
    18             Console.ReadKey();
    19         }
    20     }
    21 
    22     interface IIntroduce
    23     {
    24         void SayHi();
    25         void DescribeMyself();
    26         void SayGoodbye();
    27 
    28     }
    29 
    30    class SoftwareEngineer : IIntroduce
    31     {
    32         public void DescribeMyself()
    33         {
    34             Console.WriteLine("I'm a software engineer !"); 
    35         }
    36 
    37         public void SayGoodbye()
    38         {
    39             Console.WriteLine("Goodbye !");
    40         }
    41 
    42         public void SayHi()
    43         {
    44             Console.WriteLine("Hi !");
    45         }
    46 
    47     }
    48 
    49 
    50    class Teacher : IIntroduce
    51     {
    52         public void DescribeMyself()
    53         {
    54             Console.WriteLine("I'm a Teacher !");
    55         }
    56         public void SayGoodbye()
    57         {
    58             Console.WriteLine("Goodbye !");
    59         }
    60         public void SayHi()
    61         {
    62             Console.WriteLine("Hi !");
    63         }
    64     }

    2. 运行结果:

  • 相关阅读:
    python基础 条件和循环
    git基本使用(搭建Git服务器)
    面试题整理
    node nvm npm nrm 安装
    onmouse事件
    webpack
    web前端UI框架
    javascript cookie
    三大家族,offset,scroll,client
    clientTop,scrollTop,兼容
  • 原文地址:https://www.cnblogs.com/ChengWenHao/p/Jiekou.html
Copyright © 2020-2023  润新知