Class organization
The way to organize an actual class will differ between organizations, but the key is consistency. The way you will be shown to organize a class in this section is just one possible way. It is the way that I have most commonly encountered in the workplace.
The way to organize a class file is as follows:
- Class file comments
- Using statements
- The namespace
- The class
- Fields
- The constructor
- Properties
- Private methods
- Public methods
As you can see, this ordering makes it easy to know where in the code to look for class components. To make organization even easier, you can use regions. Regions are collapsible code used to group items together. When you have a long class file, regions can help to make your code much easier to work on – even more so when constructors, properties, and methods are collapsed with them.
The following code shows how you could organize your class files as we’ve spoken about:
...