本文介绍了如何在C#中动态更改对象的类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个名为Visitor的基类,它有2个子类Subscriber和NonSubscriber.

Suppose I have a base class named Visitor, and it has 2 subclass Subscriber and NonSubscriber.

首先,访问者是从非订阅者开始的,即

At first a visitor is start off from a NonSubscriber, i.e.

NonSubscriber mary = new NonSubscriber();

然后稍后,该玛丽"订阅了一些服务,我想将玛丽"的类型更改为订户.

Then later on this "mary" subscribed to some services, and I want to change the type of "mary" to Subscriber.

传统的做法是什么?

推荐答案

无法做到这一点.对不起.C#不是动态语言.

can't do that. sorry. C# is not a dynamic language.

这篇关于如何在C#中动态更改对象的类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 23:51