PC Review


Reply
Thread Tools Rate Thread

compile error problems

 
 
Tony
Guest
Posts: n/a
 
      18th Jun 2008
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


 
Reply With Quote
 
 
 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      18th Jun 2008
On Jun 18, 3:25*pm, "Tony" <johansson.anders...@telia.com> wrote:
> 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
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
STLPort in VC++ - Compile problems PangFromChina Microsoft VC .NET 1 9th May 2006 12:11 PM
VBAProject name compile error, not defined at compile time Matthew Dodds Microsoft Excel Programming 1 13th Dec 2005 07:17 PM
Compile problems... AMeador Microsoft C# .NET 0 20th Apr 2005 02:35 AM
A2K compile problems in XP Microsoft Access VBA Modules 1 4th Oct 2004 03:22 AM
compile problems Mike Microsoft C# .NET 5 7th Aug 2003 12:08 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:11 PM.