Synopsis: | Do not overload any 'modifying' operators on a class type |
Language: | C# |
Severity Level: | 6 |
Category: | Object oriented |
Description: |
In this context the 'modifying' operators are those that have a corresponding assignment operator, i.e. the non-unary versions of There is very little literature regarding operator overloading in C#. Therefore it is wise to approach this feature with some caution. Overloading operators on a Consider a
public static void AddTwenty (Foo f) { f += 20; }
Then this function has no net effect:
{ Foo bar = new Foo(5); AddTwenty (bar); // note that 'bar' is unchanged // the Foo object with value 25 is on its way to the GC... } The exception to this rule is a |