zoukankan      html  css  js  c++  java
  • 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. 运行结果:

  • 相关阅读:
    MathType中怎么设置字体默认颜色
    MathType二次偏导怎么表示
    简单几步让你的公式逼格爆表!
    登陆
    输入框
    表单
    窗体
    hello world
    net 代码生成
    Sql_server四种执行ExecuteReader、ExecuteNonQuery、ExecuteScalar、DataSet.docx
  • 原文地址:https://www.cnblogs.com/ChengWenHao/p/Jiekou.html
Copyright © 2011-2022 走看看