471,356 Members | 1,519 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,356 software developers and data experts.

compile error problems

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<Tanimals = new List<T>();

public List<TAnimal
{
get { return animals; }
}

IEnumerator IEnumerable.GetEnumerator()
{
return animals.GetEnumerator();
}

public IEnumerator<TGetEnumerator()
{
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<CowGetCows()
{
Farm<CowcowFarm = new Farm<Cow>();
foreach (T animal in animals)
{
if (animal is Cow)
cowFarm.animals.Add(animal as Cow);
}

return cowFarm;
}
}
}

//Tony
Jun 27 '08 #1
1 1364
On Jun 18, 3:25*pm, "Tony" <johansson.anders...@telia.comwrote:
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
It's hard to say for sure because you haven't included your using
directives, but I suspect the problem is that you're missing:
using System.Collections;

That's required to let the compiler know about the nongeneric
IEnumerator type.

After that you'll need to add a Feed method to Animal.

Jon
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Carmine Cairo | last post: by
5 posts views Thread by Brice Prunier | last post: by
9 posts views Thread by serge | last post: by
10 posts views Thread by Chris LaJoie | last post: by
2 posts views Thread by Gustavo | last post: by
6 posts views Thread by Kevin Atherton | last post: by
4 posts views Thread by Siegfried Heintze | last post: by
1 post views Thread by electrixnow | last post: by
15 posts views Thread by steve yee | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.