Classes - C# Coding Standard 9

Classes are most used types in C#. Please find below the standards which we need to follow while working with classes.

             Name the class with non or noun phrases 

             Do not begin class name with a prefix “C” 

             For generic type class parameters, use descriptive name that starts with “T” 

             If class is inheriting any base class, child class name should suffix with the base class. For example, if class Employee is inheriting Company class then Employee class name should be EmployeeCompany not just Employee. 

             When creating class for custom attributes, class name should suffix with Attribute. For example, if Employee class contains only custom attributes then class name should be EmployeeAttribute. 

             For custom event handler class, add the suffix EventHandler to the class name 

             Add the suffix EventArgs to custom event args class 

             For delegates, add the suffix Callback to the delegate name 

             For custom exception class, add the suffix Exception to the class name 

             If your class implements any one of the interfaces from ICollection, IList, IEnumerable, ICollection<T>, IList<T>, or IEnumerable<T> then add suffix Collection to your class name 

             For abstract classes, you can define protected or an internal constructor, but you should not define public or protected internal constructor 

             Partial classes defined in multiple files. Each file name should suffix with letter “P” followed by ordinal number. For example, if Employee class defines as partial class in multiple files then each file should be named as EmployeeP1, EmployeeP2,...etc 

             Static classes should be declared as abstract or sealed