By implementing operators for your classes in C #, you are not actually overloading operators. You just implement them for the first time. These methods, like any other, but with special syntax. Instead of calling c = Add(a, b) you call c = a + b , where + is the operator (method) that returns the value.
By implementing the following methods, the &= |= and ^= methods were automatically implemented.
public class MyClass { public static MyClass operator &(MyClass left, MyClass right) { return new MyClass(); } public static MyClass operator |(MyClass left, MyClass right) { return new MyClass(); } public static MyClass operator ^(MyClass left, MyClass right) { return new MyClass(); } } var a = new MyClass(); var b = new MyClass(); var c = a & b; var d = a | b; var e = a ^ b; a &= b;
Overloading is performed at compile time. This ensures that a particular method will be called based on the method name, type of parameter and quantity.
Overiding is performed at runtime. It allows you to call a subclass method instead of the parent method, even if the instance was considered as the parent class.
Christopher harris
source share