Using C# Operators

C# provides several operators for arithmetic, logical, increment, decrement, and other operations. C# also provides for shorthand notations for common situations such as adding an amount to a variable. In addition, most of the C# operators can be overloaded by the developer. Overloading enables the developer to specify the behavior for the operator when applied to a specific type. Overloading will be covered later in this chapter. Table 3.1 provides a listing of all operators for C#.

Table 3.1. C# Operators
CategoryOperatorDescriptionCan Overload?
Arithmetic+AdditionYes
 -SubtractionYes
 *MultiplicationYes
 /DivisionYes
 %Modulus remainderYes
Logical&Bitwise ANDYes
 |Bitwise ORYes
 ^Bitwise exclusive ORYes
 !Logical negationYes
 ~Bitwise ...

Get Microsoft® Visual C#® .NET 2003 Unleashed 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.