C#修魔

C#魔帅-lesson_04-接口

2018-11-14  本文已影响0人  疯帮主

接口(Interface)

接口定义了所有类继承接口时应遵循的语法合同。
接口定义了语法合同 "是什么" 部分,派生类定义了语法合同 "怎么做" 部分。

定义接口

通常接口命令以 I 字母开头

interface IMyInterface
{
    void MethodToImplement();
}

接口继承

interface IParentInterface
{
    void ParentInterfaceMethod();
}

interface IMyInterface : IParentInterface
{
    void MethodToImplement();
}

class InterfaceImplementer : IMyInterface
{
  //实现
}

参考文档:http://www.runoob.com/csharp/csharp-interface.html

上一篇下一篇

猜你喜欢

热点阅读