T
Tony Johansson
Hello!
Assume you have this generic Dictionary class with key, value pair the first
part is the key and the second part is the value part.
The key value is a string and the value part is the Car.
Dictionary<string, Car> directory = new Dictionary<string, Car>();
Now to my question assume that you have a derived class called BMW below the
base class Car.
Is it then legal to use BMW instead of Car because BMW is a Car or are you
obliged to use exactly
the same type (here Car) as the one you used when you instansiated the
object directory of type Dictionary.
I assume that this is the main point of using generics to use exactly the
same type because if this was not the case you could all the same use the
general class.
class Car
{
....
}
class BMW : Car
{
....
}
//Tony
Assume you have this generic Dictionary class with key, value pair the first
part is the key and the second part is the value part.
The key value is a string and the value part is the Car.
Dictionary<string, Car> directory = new Dictionary<string, Car>();
Now to my question assume that you have a derived class called BMW below the
base class Car.
Is it then legal to use BMW instead of Car because BMW is a Car or are you
obliged to use exactly
the same type (here Car) as the one you used when you instansiated the
object directory of type Dictionary.
I assume that this is the main point of using generics to use exactly the
same type because if this was not the case you could all the same use the
general class.
class Car
{
....
}
class BMW : Car
{
....
}
//Tony