Is it possible to assign a base class object to a

2019-01-01 13:10发布

Is it possible to assign a base class object to a derived class reference with an explicit typecast in C#?.

I have tried it and it creates a run-time error.

19条回答
孤独寂梦人
2楼-- · 2019-01-01 14:06

As everyone here said, that's not possible directly.

The method I prefer and is rather clean, is to use an Object Mapper like AutoMapper.

It will do the task of copying properties from one instance to another (Not necessarily the same type) automatically.

查看更多
登录 后发表回答