Search code examples
c#class-design

Access to an inner struct/class in C#


I have a class that has an inner struct/class (I have decided which yet, if it matters for this I will use that) I want the inner class to be accessed from other classes but only constructed by the outer class. Is this possible?

Thanks


Solution

  • The closest you can get is an internal constructor, unfortunately. While private and protected members of an outer class are available to an inner class, the opposite is not true.