请各位大大帮忙解决下一个泛型类的问题
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace Ch12Ex04
{
public class Farm <T> : IEnumerable <T>
where T : Animal
{
private List <T> animals = new List <T> ();
public List <T> Animals
{
get
{
return animals;
}
}
//实现IEnumerable接口
public IEnumerable <T> GetEnumrator()
{
return animals.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return animals.GetEnumerator();
}
//迭代两个基类方法
public void MakeNoises()
{
foreach (T animal in animals)
{
animal.MakeANoise();
}
}
public void FeedTheAnimals()
{
foreach (T animal in animals)
{
animal.Feed();
}