Using Inner classes in C#

前端 未结 9 1909
粉色の甜心
粉色の甜心 2020-12-02 18:40

What are the best practices regarding the use and structure of inner classes in C#.

For instance if I have a very large base class and two large inner classes should

9条回答
  •  失恋的感觉
    2020-12-02 19:29

    In my opinion inner classes, if needed at all, should be kept small and used internally by that class only. If you use Relfector on the .NET framework you'll see them used a lot just for that purpose.

    If your inner classes are getting too big I would definitely move them out into separate classes/codefiles somehow if only for maintainability. I have to support some existing code where someone thought it was a great idea to use inner classes within inner classes. It resulted in an inner class hierarchy running 4 - 5 levels deep. Needless to say the code is impenetrable and takes ages to understand what you are looking at.

提交回复
热议问题