Chapter 22

Operator overloading

After completing this chapter, you will be able to:

  • Explain how operator overloading works.

  • Write increment and decrement operators for your own types.

  • Understand the nuances of operators in structs and classes.

  • Explain the need to implement some operators as pairs.

  • Override operators in a struct, and implement custom equality operators.

  • Implement implicit and explicit conversion operators for your own types.

The examples throughout this book make great use of the standard operator symbols (such as + and ) to perform standard operations (such as addition and subtraction) on types (such as int and double). Many of the built-in types come with their own predefined behaviors for each operator. You can also define ...

Get Microsoft Visual C# Step by Step, 10th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.