using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
/*
接口Interface
接口定义了属性、方法和事件 ,这些都是接口成员。接口只包含成员的声明。成员的定义是派生类的责任。
接口提供了派生类应遵循的标准结构。使得实现接口的类或结构在形式上保持一致
*/
//接口1
interface IParentInterface
{
void ParentInterfaceMethod();
}
//接口2继承接口1
interface IMyInterface : IParentInterface
{
void MethodToImplement();
}
//重写所有接口的函数
class InterfaceImplementer : IMyInterface
{
//重写接口2
public void MethodToImplement()
{
Console.WriteLine("MethodToImplemnet()called.");
}
//重写接口1
public void ParentInterfaceMethod()
{
Console.WriteLine("ParentInterfaceMethod() called.");
}
//主函数入口
static void Main()
{
InterfaceImplementer iImp = new InterfaceImplementer();
iImp.MethodToImplement();
iImp.ParentInterfaceMethod();
}
}
C#的接口(interface)的用法和意义
猜你喜欢
转载自blog.csdn.net/weixin_50188452/article/details/114889478
今日推荐
周排行