【发布时间】:2010-09-15 18:47:23
【问题描述】:
我有两个类:一个基类(动物)和一个派生自 it (Cat).Base 类包含一个以 List 作为输入参数的虚拟方法 Play。类似这样的东西
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication9
{
class Animal
{
public virtual void Play(List<Animal> animal) { }
}
class Cat : Animal
{
public override void Play(List<Animal> animal)
{
}
}
class Program
{
static void Main(string[] args)
{
Cat cat = new Cat();
cat.Play(new List<Cat>());
}
}
}
当我编译上述程序时,我得到以下错误
错误 2 参数 1:无法从 'System.Collections.Generic.List' 转换为 'System.Collections.Generic.List'有没有办法做到这一点?
【问题讨论】:
-
首先要做的是将 List 参数更改为 IEnumerable 参数。