Chapter 9. Operator Overloading
Operator overloading is used to add implicit or explicit operator behavior to types. Primitive types, such as integers, floats, and doubles, implicitly support most operators, including mathematical and logical operators. Other commonly used types, such as strings, support a limited set of operators. This intrinsic integration of standard operators in primitive types makes using built-in types convenient. You might want to use a user-defined type just as conveniently. Unfortunately, the C# compiler does not know how to apply standard operators to user-defined classes. For example, what does zclass+zclass mean? Operator overloading teaches the compiler how to interpret standard operators in the context of a user-defined ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access