using System;
using System.Collections.Generic;
using System.Text;
namespace Test
{
interface IA
{
void PlayA();
string Name { get;set;}
}
interface IB
{
void PlayB();
string this[int n] { get;}
}
abstract class TC
{
public abstract void PlayC();
}
class TD
{
public void PlayD()
{
Console.WriteLine("TD 执行");
}
}
class DEntity : TC, IB, IA
{
private string name = "小明";
private string[] ids = new string[] { "AX", "BX", "CX" };
public void PlayA() { Console.WriteLine("IA Function 执行"); }
public void PlayB() { Console.WriteLine("IB Function 执行"); }
public override void PlayC() { Console.WriteLine("TC Function 执行"); }
string this[int n] { get { return ids[n]; } }
public string Name
{
get { return name; }
set { name = value; }
}
}
class Program
{
static void Main(string[] args)
{
IA ia = new DEntity();
Console.WriteLine(ia.Name);
IB ib = new DEntity();
Console.WriteLine(ib[0]);
TC tc = new DEntity();
tc.PlayC();
}
}
}
//继承规则1 1个类:1个类+n个接口
//继承规则2 接口:n个接口
//接口是比抽象类更抽象的“特殊类”,只能声明方法、属性和索引器,不能有其他任何成员。
//接口成员不能有任何修饰符,虽然默认为public。
//特点:干净! 抽象类和普通类的区别,只是没有对“方法”的实现。
C# 接口的继承模式
猜你喜欢
转载自blog.csdn.net/CQL_K21/article/details/87566837
今日推荐
周排行