程序没报错,为什么运行没有结果?求大神指教
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp8
{
public class Pet
{
public Pet(string name, uint age, string food)
{
_name=name;
_age=age;
_food=food;
}
protected string _name;
protected uint _age;
protected string _food;
protected string Voice;
virtual public void PrintName()
{
Console.WriteLine("Pet's name is" + _name);
Console.WriteLine("Pet's age is" + _age);
Console.WriteLine("Pet's favorit food is" + _food);
}
virtual public void PrintVoice()
{
Console.WriteLine("Pet's voice is spking" );
}
}
public class Dog:Pet
{
public Dog(string name, uint age, string food) : base(name, age, food)
{
}
override public void PrintVoice()
{
Console.WriteLine(_name + "的叫声是:" + "汪汪汪");
}
}
public class Cat:Pet
{
public Cat(string name, uint age, string food) : base(name, age, food)
{
}
override public void PrintName()
{
Console.WriteLine("宠物的名字是:" + _name);
Console.WriteLine("宠物的年龄是" + _age);
Console.WriteLine("宠物最喜欢的食物是" + _age);
}
override public void PrintVoice()
{
Console.WriteLine(Name + "的叫声是:" + "喵喵喵");
}
}
class Program
{
static void Main(string[] args)
{
Pet[] pets = new Pet[] { new Dog("旺财",7,"肉骨头"), new Cat("阿福", 3, "小鱼干") };
for(int i=0; i<pets.Length; i++)
{
pets[i].PrintName();
}
for (int y = 0; y < pets.Length; y++)
{
pets[y].PrintVoice();
}
}
}
}