Is it possible to have a private class?

前端 未结 4 1253
隐瞒了意图╮
隐瞒了意图╮ 2021-01-12 13:40

I always wonder if it is possible to have a private class? And, what would be the point of having such class?

Thanks for helping.

4条回答
  •  天涯浪人
    2021-01-12 14:03

    Yes you can - usually they are nested classes inside another type. This means you can aggregate logic into a nested class without exposing the class to anything else. Internal is also useful for nested classes.

    Note however that there are some arguments against a design requiring nested classes - I tend to use them when they seem a good fit though.

提交回复
热议问题