Using Inner classes in C#

前端 未结 9 1913
粉色の甜心
粉色の甜心 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:16

    I personally like to have one class per file, and the inner classes as part of that file. I believe inner classes should typically (nearly always) be private, and are an implementation detail of the class. Having them in a separate file confuses things, IMO.

    Using code regions to wrap around the inner classes and hide their details works well for me, in this case, and keeps the file from being difficult to work with. The code regions keep the inner class "hidden", and since it's a private implementation detail, that's fine with me.

提交回复
热议问题