In any programming language, we may use several type of elements like
classes, variables, properties, methods, enums, structs,...etc. To maintain the
consistency across code base and to improve the code readability, we should
declare all these elements in a proper order. Today we discuss what is the good
practice to declare elements in a proper format.
The order of the C# class file should be
“using” statements followed by namespaces.
Any namespace should follow below order
while declaring any elements.
C# class should follow below order to
declare the elements.
If there are more than one elements of sane type, then they should
follow the order based on their accessibility level as below.
Enums, Interfaces, and Structs need not to be declared only at class
level, they can also declare at namespace level also. Use #region/#endregion to
group namespace and class level elements.