Cast to Extended Class in C# (dotnet 3.5<)
- by csharpnoob
Hi,
i'm not sure if it's possible.
I have a class car and a class mycar extended from class car.
Class mycar has also a string list. Only difference.
How can i cast now any car object to a mycar object without assigning all
attributes each by hand. Like:
Car car = new Car();
MyCar mcar = (MyCar) car;
or
MyCar mcar = new MyCar(car);
or however i can extend car with own variables and don't have to do always
Car car = new Car();
MyCar mcar = new MyCar();
mcar.name = car.name;
mcar.xyz = car.xyz;
...
Thanks.