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

前端 未结 4 2135
小蘑菇
小蘑菇 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 08:02

    A better solution would have ICar declare a GenericCarMethod() and have Bmw and Toyota override it. In general, it's not a good design practice to rely on downcasting if you can avoid it.

提交回复
热议问题