How to change the class of an object dynamically in C#?

后端 未结 10 1371
囚心锁ツ
囚心锁ツ 2021-01-05 17:09

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.

<         


        
10条回答
  •  长情又很酷
    2021-01-05 17:53

    You will have to create a new mary = new Subscriber(); and copy all relevant properties.

    But a better approach might be to model it differently: Give Visitor a list of subscriptions. An empty list means a NonSubscriber.

提交回复
热议问题