TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
C# Coding Standard
Search

Category: Object oriented

Synopsis:Object oriented programming


Description:

Coding Rules

NameCheckedSynopsis
7@101 Checked automatically with code checker Declare all fields (data members) private
7@102 Checked automatically with code checker Prevent instantiation of a class if it contains only static members
7@105 Checked automatically with code checker Explicitly define a protected constructor on an abstract base class
7@106 Checked automatically with code checker Make all types internal by default
7@107 Checked automatically with code checker Limit the contents of a source code file to one type
7@108 Use using statements instead of fully qualified type names
7@201 Selection statements (if-else and switch) should be used when the control flow depends on an object's value; dynamic binding should be used when the control flow depends on the object's type
7@301 All variants of an overloaded method shall be used for the same purpose and have similar behavior
7@303 Checked automatically with code checker If you must provide the ability to override a method, make only the most complete overload virtual and define the other operations in terms of it
7@304 Checked automatically with code checker Only use optional arguments to replace overloads
7@401 Specify methods using preconditions, postconditions, exceptions; specify classes using invariants
7@402 Use code to describe preconditions, postconditions, exceptions, and class invariants
7@403 It shall be possible to use a reference to an object of a derived class wherever a reference to that object's base class object is used
7@404 Checked automatically with code checker Don't hide inherited members with the new keyword
7@501 Checked automatically with code checker Do not overload any 'modifying' operators on a class type
7@502 Checked automatically with code checker Do not modify the value of any of the operands in the implementation of an overloaded operator
7@503 If you implement one of operator==(), the Equals method or GetHashCode(), implement all three
7@504 Use a struct when value semantics are desired
7@520 Checked automatically with code checker Override the GetHashCode method whenever you override the Equals method.
7@521 Checked automatically with code checker Override the Equals method whenever you implement the == operator, and make them do the same thing
7@522 Checked automatically with code checker Override the Equals method any time you implement the IComparable Interface
7@523 Checked automatically with code checker Do not throw exceptions from the Equals or GetHashCode methods or the equality operator (==)
7@525 Checked automatically with code checker Override the Equals method on value types.
7@526 Checked automatically with code checker Reference types should NOT override the equality operators ('==' and '!=')
7@530 Checked automatically with code checker Implement operator overloading for the equality (==), not equal (!=), less than (<), and greater than (>) operators when you implement IComparable
7@531 Checked automatically with code checker Overload the equality operator (==), when you overload the addition (+) operator and/or subtraction (-) operator
7@532 Checked automatically with code checker Implement all relational operators (<, <=, >, >=) if you implement any
7@533 Checked automatically with code checker Do NOT use the Equals method to compare diffferent value types, but use the equality operators instead.
7@601 Allow properties to be set in any order
7@602 Use a property rather than a method when the member is a logical data member
7@603 Checked automatically with code checker Use a method rather than a property when this is more appropriate
7@604 Do not create a constructor that does not yield a fully initialized object
7@608 Always check the result of an as operation
7@609 Checked automatically with code checker Use the correct way of casting
7@610 Checked automatically with code checker Use explicit interface implementation only to prevent name-clashing or to support optional interfaces
7@611 Checked automatically with code checker Use generic constraints if applicable
7@700 Do not ignore method results