Re: Implementing an interface with qualified templates
- From: "Nicholas Paldino [.NET/C# MVP]" <mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 29 Jun 2006 00:49:33 -0400
Dave,
Why not just declare the interface as generic?
public class Animal
{}
public class Fish : Animal
{}
public interface IZoo<T> where T : Animal
{
List<T> Animals { get; }
void Feed(T a);
}
public Aquarium : IZoo<Fish>
{
}
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx
"Dave Booker" <dbooksta@xxxxxxxxxxxxxxxx> wrote in message
news:0C1D6E11-3CF6-489A-B5A2-56A4518C53DF@xxxxxxxxxxxxxxxx
I want to do something like this:
public class Animal;
public interface IZoo
{
List<Animal> Animals { get; }
void Feed(Animal a);
}
public Aquarium<FISH> : IZoo where FISH : Animal
{
public List<FISH> Animals { get ...;}
public void Feed(FISH a) {...}
}
It seems like this should be possible, because FISH are guaranteed to be
Animals. I can dodge the generic collection problem by substituting an
ArrayList for the List<>, but I don't see why I have to. And then there's
the problem of the function argument.
Is there any way to implement a (non-templated) interface with a qualified
template, like what I'm suggesting here?
.
- Prev by Date: Re: Strings vs. Ints
- Next by Date: Re: Call DLL from a Windows form
- Previous by thread: Re: Implementing an interface with qualified templates
- Next by thread: RE: Implementing an interface with qualified templates
- Index(es):
Relevant Pages
|