T
Tony
Hello!
I have some classes below.
I have also a generic collection class with this class header definition.
public class Farm<T> : IEnumerable<T> where T : Animal {...}
Now to my question according to a book that I read it says:
"The type of this list is determined by the type parameter T that is passed
to Farm<T> and
is constraned to be or inherit from Animal."
Because class Animal is abstract it's not possible to create an instance of
that class.
So what does this where T : Animal mean
I assume it means that T can be of a type derived from Animal or Animal
itself but
in some cases as in my case Animal itself are not allowed because it's an
abstract class.
Does my conclusion sound reasonable?
public abstract class Animal {. . .}
public class Chicken : Animal {...}
public class Cow : Animal {...}
public class SuperCow : Cow {...}
//Tony
I have some classes below.
I have also a generic collection class with this class header definition.
public class Farm<T> : IEnumerable<T> where T : Animal {...}
Now to my question according to a book that I read it says:
"The type of this list is determined by the type parameter T that is passed
to Farm<T> and
is constraned to be or inherit from Animal."
Because class Animal is abstract it's not possible to create an instance of
that class.
So what does this where T : Animal mean
I assume it means that T can be of a type derived from Animal or Animal
itself but
in some cases as in my case Animal itself are not allowed because it's an
abstract class.
Does my conclusion sound reasonable?
public abstract class Animal {. . .}
public class Chicken : Animal {...}
public class Cow : Animal {...}
public class SuperCow : Cow {...}
//Tony