相关疑难解决方法(0)

为什么我不能在显式实现接口的类中调用方法?

这是故事.我创建了一个界面IVehicle.我明确地在我的类中实现了接口Vehicle.cs.

这是我的界面:

Interface IVehicle
{
        int getWheel();
}
Run Code Online (Sandbox Code Playgroud)

这是我的班级:

class Vehicle: IVehicle
{

     public int IVehicle.getWheel()
     {
         return wheel;
     }

     public void printWheel()
     {
         Console.WriteLine(getWheel());
     }
}
Run Code Online (Sandbox Code Playgroud)

请注意,这getWheel()是明确实现的.现在,当我尝试在我的Vehicle类中调用该方法时,我收到一个错误,指示getWheel()当前上下文中不存在该错误.有人能帮助我理解我做错了什么吗?

c# explicit interface

37
推荐指数
2
解决办法
1万
查看次数

标签 统计

c# ×1

explicit ×1

interface ×1