G
Guest
Hi. I want the parameter type of a function to be the same type of the class.
One solution would be:
class Animal<TAnimal> where TAniman : Animal
{
public virtual void DoSomethingToTheAnimal(TAnimal animal)
{
////
}
}
class Dog : Animal<TAniman> where TAnimal : Dog
{
}
But I prefer not to require the user to include a statement like
where TAnimal : Dog
every time a class is inherited. Is there a better way to do this?
Thanks
Matt Brown
One solution would be:
class Animal<TAnimal> where TAniman : Animal
{
public virtual void DoSomethingToTheAnimal(TAnimal animal)
{
////
}
}
class Dog : Animal<TAniman> where TAnimal : Dog
{
}
But I prefer not to require the user to include a statement like
where TAnimal : Dog
every time a class is inherited. Is there a better way to do this?
Thanks
Matt Brown