本文介绍了将父级转换为子级,但将数据保留在父级中并转移到子级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 如何将父类强制转换为子类但不覆盖父类中的现有数据? 如果我有这个数据,那么已经在基类实例中的数据将是用新的Derived()覆盖。 Base derivedInstance = new Derived(); 派生商品=(派生)derivedInstance; 希望您理解我的问题? 我尝试过: 基地derivedInstance = new Derived(); 派生好=(衍生)derivedInstance; 解决方案 How to cast parent class to child but not overwriting existing data in parent class ?If I have this than data which is already in Base class instance will be overwritten with new Derived(). Base derivedInstance = new Derived();Derived good = (Derived)derivedInstance;Hope You understand my question ?What I have tried:Base derivedInstance = new Derived();Derived good = (Derived)derivedInstance; 解决方案 这篇关于将父级转换为子级,但将数据保留在父级中并转移到子级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-12 14:06