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

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

1.代码(入门举例)

     class Program
{
static void Main(string[] args)
{
Console.WriteLine("-------------------------------------");
IIntroduce iSE = new SoftwareEngineer();
iSE.SayHi();
iSE.DescribeMyself();
iSE.SayGoodbye(); Console.WriteLine("-------------------------------------");
IIntroduce iTc = new Teacher();
iTc.SayHi();
iTc.DescribeMyself();
iTc.SayGoodbye(); Console.ReadKey();
}
} interface IIntroduce
{
void SayHi();
void DescribeMyself();
void SayGoodbye(); } class SoftwareEngineer : IIntroduce
{
public void DescribeMyself()
{
Console.WriteLine("I'm a software engineer !");
} public void SayGoodbye()
{
Console.WriteLine("Goodbye !");
} public void SayHi()
{
Console.WriteLine("Hi !");
} } class Teacher : IIntroduce
{
public void DescribeMyself()
{
Console.WriteLine("I'm a Teacher !");
}
public void SayGoodbye()
{
Console.WriteLine("Goodbye !");
}
public void SayHi()
{
Console.WriteLine("Hi !");
}
}

2. 运行结果:
C# -- 接口 (关键字:interface)

上一篇:记一次ss无法上网的排查


下一篇:Java基础学习笔记十五 集合、迭代器、泛型