![]() |
Overload Appropriate Operators
Operator overloading is like sugar: a little is sweet, but a lot will make
you sick. Ensure that you only use this technique for situations that make sense. Implement operator + Notice that the method is public static and takes both operators as arguments. Code:
public static Vertex3d operator +(Vertex3d a, Vertex3d b)as well. Implement operator == and operator != These should always be implemented as a pair. Because we’ve already implemented a useful Equals() method, just call that instead. Code:
public static bool operator ==(Vertex3d a, Vertex3d b)both a and b, as in this example: Code:
public static bool operator ==(CatalogItem a, CatalogItem b) |
| All times are GMT +5.5. The time now is 21:08. |