案例来自:unity与c++网络开发实践
using System;
namespace LearnInterface
{
public interface Iworker { void work(string a); }
class AIReal1 : Iworker
{
public void work(string a)
{
Console.WriteLine("我的名字是仿真人1"+"我的工作是"+a);
}
}
class AIReal2 : Iworker
{
public void work(string a)
{
Console.WriteLine("我的名字是仿真人2" + "我的工作是" + a);
}
}
class Program
{
static void Main(string[] args)
{
//通过接口实例化ai1
Iworker ai1 = new AIReal1();
//通过接口实例化ai2
Iworker ai2 = new AIReal2();
// 通过接口实现ai1
ai1.work("美工");
// 通过接口实现ai2
ai2.work("编程");
Console.WriteLine("Hello World!");
}
}
}