0
C#支持区分具有相同名称的方法的内置机制。下面是一个简单的例子,显示它如何工作:C#中显式接口实现的优点是什么?
interface IVehicle{
//identify vehicle by model, make, year
void IdentifySelf();
}
interface IRobot{
//identify robot by name
void IdentifySelf();
}
class TransformingRobot : IRobot, IVehicle{
void IRobot.IdentifySelf(){
Console.WriteLine("Robot");
}
void IVehicle.IdentifySelf(){
Console.WriteLine("Vehicle");
}
}
这种区别的用例或好处是什么?我真的需要区分实现类的抽象方法吗?