T
Tony
Hello!
I get the following compile error below in the complete program below.
Any suggestion
Error 1 Using the generic type 'System.Collections.Generic.IEnumerator<T>'
requires '1' type arguments
C:\tony\ConsoleApplication15\ConsoleApplication15\Program.cs 80 9
ConsoleApplication15
namespace ConsoleApplication15
{
class Program
{
static void Main(string[] args)
{
}
}
public abstract class Animal
{
string name;
public Animal(string name)
{
this.name = name;
}
public string Name
{
get { return name; }
}
public abstract void MakeANoise();
}
public class Chicken : Animal
{
public Chicken(string name) : base(name)
{}
public override void MakeANoise()
{
Console.WriteLine("{0} says 'cluck!'", Name);
}
}
public class Cow : Animal
{
public Cow(string name) : base(name)
{ }
public override void MakeANoise()
{
Console.WriteLine("{0} says 'moo!'", Name);
}
}
public class SuperCow : Cow
{
public SuperCow(string name) : base(name)
{ }
public void Fly()
{
Console.WriteLine("{0} is flying!", Name);
}
public override void MakeANoise()
{
Console.WriteLine("{0} says 'here I come to save the day!'",
Name);
}
}
public class Farm<T> : IEnumerable<T>
where T : Animal
{
private List<T> animals = new List<T>();
public List<T> Animal
{
get { return animals; }
}
IEnumerator IEnumerable.GetEnumerator()
{
return animals.GetEnumerator();
}
public IEnumerator<T> GetEnumerator()
{
return animals.GetEnumerator();
}
public void MakeNoises()
{
foreach (T animal in animals)
{
animal.MakeANoise();
}
}
public void FeedTheAnimals()
{
foreach (T animal in animals)
{
animal.Feed();
}
}
public Farm<Cow> GetCows()
{
Farm<Cow> cowFarm = new Farm<Cow>();
foreach (T animal in animals)
{
if (animal is Cow)
cowFarm.animals.Add(animal as Cow);
}
return cowFarm;
}
}
}
//Tony
I get the following compile error below in the complete program below.
Any suggestion
Error 1 Using the generic type 'System.Collections.Generic.IEnumerator<T>'
requires '1' type arguments
C:\tony\ConsoleApplication15\ConsoleApplication15\Program.cs 80 9
ConsoleApplication15
namespace ConsoleApplication15
{
class Program
{
static void Main(string[] args)
{
}
}
public abstract class Animal
{
string name;
public Animal(string name)
{
this.name = name;
}
public string Name
{
get { return name; }
}
public abstract void MakeANoise();
}
public class Chicken : Animal
{
public Chicken(string name) : base(name)
{}
public override void MakeANoise()
{
Console.WriteLine("{0} says 'cluck!'", Name);
}
}
public class Cow : Animal
{
public Cow(string name) : base(name)
{ }
public override void MakeANoise()
{
Console.WriteLine("{0} says 'moo!'", Name);
}
}
public class SuperCow : Cow
{
public SuperCow(string name) : base(name)
{ }
public void Fly()
{
Console.WriteLine("{0} is flying!", Name);
}
public override void MakeANoise()
{
Console.WriteLine("{0} says 'here I come to save the day!'",
Name);
}
}
public class Farm<T> : IEnumerable<T>
where T : Animal
{
private List<T> animals = new List<T>();
public List<T> Animal
{
get { return animals; }
}
IEnumerator IEnumerable.GetEnumerator()
{
return animals.GetEnumerator();
}
public IEnumerator<T> GetEnumerator()
{
return animals.GetEnumerator();
}
public void MakeNoises()
{
foreach (T animal in animals)
{
animal.MakeANoise();
}
}
public void FeedTheAnimals()
{
foreach (T animal in animals)
{
animal.Feed();
}
}
public Farm<Cow> GetCows()
{
Farm<Cow> cowFarm = new Farm<Cow>();
foreach (T animal in animals)
{
if (animal is Cow)
cowFarm.animals.Add(animal as Cow);
}
return cowFarm;
}
}
}
//Tony