C#: Method to return object whose concrete type is determined at runtime?

前端 未结 4 2111
小蘑菇
小蘑菇 2021-02-10 07:10

I\'m thinking about designing a method that would return an object that implements an interface but whose concrete type won\'t be know until run-time. For example suppose:

4条回答
  •  隐瞒了意图╮
    2021-02-10 07:53

    You would want just a virtual method, SpecificationMethod, which is implemented in each class. I recommend reading FAQ Lite's content on inheritence. The design method's he mentions can be applied to .Net as well.

提交回复
热议问题