Next: Another Widget is created. And finally we add the 2 widgets together with a single "+" operator.
So: When we add the 2 Widgets together, a new Widget is returned. This is conceptually the same way the string type works.
C# program that uses operator keyword
public int _value;
public static Widget operator+(Widget a, Widget b)
// Add two Widgets together.
// ... Add the two int values and return a new Widget.
Widget widget = new Widget();
widget._value = a._value + b._value;
public static Widget operator++(Widget w)
// Increment this widget.
static void Main()
// Increment widget twice.
Widget w = new Widget();
// Create another widget.
Widget g = new Widget();
// Add two widgets.
Widget t = w + g;
Operator list. Many but not all operators in the C# language can be overloaded. This comes from the C# specification, which has more in-depth information on overloading.
Unary operators you can overload
Binary operators you can overload
Discussion. It is not necessary to overload operators on every class you create. My opinion is that overloading operators is rarely required. It helps only on types that are commonly used.
Example: In the .NET Framework itself, the string type has overloads and these are useful (this is how concatenation works).