Control Generic Type Parameter

  • Thread starter Thread starter Jinsong Liu
  • Start date Start date
J

Jinsong Liu

Hello Group:

I am playing with .NET 2.0 Generic. I have a CarsList<T> Generic
class, Is it possible that I can control what T could be? I want to
ensure the T can only be classes derived from a specific class (lets
say Car).
I understand that I can create a CarList without using Generic, but
when I add a derived class to the list, type conversion will happen,
and I will not be able to enforce type at child class level.

thanks

JL
 
I just found the answer, the "where" is what I need. I can use where
keyword to specify constraints on the types that can be used as
arguments for a type parameter defined in a generic declaration.
 
Back
Top