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");
}
}
這種區別的用例或好處是什麼?我真的需要區分實現類的抽象方法嗎?