Cast interface to its concrete implementation object or vice versa?

后端 未结 5 1030
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-01 00:31

In C#, when I have an interface and several concrete implementations, can I cast the interface to a concrete type or is concrete type cast to interface?

What are the

5条回答
  •  执念已碎
    2020-12-01 01:09

    An Interface can be the whole class, if however doesn't have to be, it is better when you create a constructor that accepts the Interface as Parameter and copy the Settings, this way you have control over what happens and what is needed.

提交回复
热议问题