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

前端 未结 4 1440
失恋的感觉
失恋的感觉 2021-02-10 07:25

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条回答
  •  -上瘾入骨i
    2021-02-10 07:37

    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.

提交回复
热议问题