What's the difference between a public constructor in an internal class and an internal constructor?

前端 未结 5 1643
礼貌的吻别
礼貌的吻别 2020-12-03 04:16

I have an internal class, an internal constructor won\'t allow it to be used in a generic collection so I changed it to public. What\'s the accessibility if you have a publi

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-03 04:53

    internal constructor are good when you don't want the client to create the instance. You'd usually want to do it if you want to control how the instance should be created.You will have to provide either a Factory to generate the class in another class within the same assembly to generate the instance internally and then expose as a property.

提交回复
热议问题