Namespace-only class visibility in C#/.NET?

前端 未结 5 1887
温柔的废话
温柔的废话 2020-12-09 14:45

In C#, can you make a class visible only within its own namespace without living in a different assembly? This seems useful for typical helper classes that shouldn\'t be use

5条回答
  •  离开以前
    2020-12-09 15:02

    Not sure if it is directly possible, but a few good ways to fake it would be:

    1) Have the classes that need this sort of stuff inherit from a single class which has the helper class as an internal class.

    2) Use extension methods and then only reference the extension methods within the namespace.

提交回复
热议问题