using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace InterfaceType
{
class Program
{
static void Main(string[] args)
{
#region 接口类型
List<IFly> ffff = new List<IFly>();
Plane p = new Plane(); //飞机
ffff.Add(p);
Bird b = new Bird(); //小鸟
ffff.Add(b);
rest r = new rest(); //敌机
ffff.Add(r);
foreach (IFly i in ffff)
{
i.Fly();
}
Console.ReadKey();
}
public interface IFly
{
void Fly();
}
public class Plane : IFly
{
public void Fly()
{
Console.WriteLine("飞机飞....");
}
}
public class rest : IFly
{
void IFly.Fly()
{
Console.WriteLine("前方2000米处,有敌机...");
}
}
public class Bird : IFly
{
void IFly.Fly()
{
Console.WriteLine("小鸟飞呀飞呀...");
}
}
}
}
#endregion
转载于:https://blog.51cto.com/mtlang/1162392