whyyouhitme_
whyyouhitme_
2018-05-28 09:22
采纳率: 65.7%
浏览 8.1k

C#对象引用对于非静态的字段、方法或属性,object.string()是必须的

amespace Traffic
{
class Program
{
static void Main(string[] args)
{
AddPassenger(new Compact());
AddPassenger(new SUV());
AddPassenger(new Pickup());
AddPassenger(new PassengerTrain());
}
static void AddPassenger(IPassengerCarrier Vehicles)
{
Console.WriteLine(Vehicle.ToString());
}
}
}

错误提示为:对象引用对于非静态的字段、方法或属性,object.string()是必须的?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • showbo
    已采纳

    static void AddPassenger(IPassengerCarrier Vehicles)
    {
    Console.WriteLine(Vehicle.ToString());

    变量名都搞错了。。===》
    Console.WriteLine(Vehicles.ToString());

    点赞 评论
  • azure190
    斌cazure 2018-05-28 09:44

    static void AddPassenger(IPassengerCarrier Vehicles)
    改成
    public void AddPassenger(IPassengerCarrier Vehicles)

    还有IPassengerCarrier是Compact,SUV,Pickup,PassengerTrain的父类么?

    点赞 评论

相关推荐