Operators
With few exceptions, the operators available in C# are syntactically and operationally the same as those in Java. Table 4-10 summarizes the operators available in both languages and highlights the differences in bold.
Table 4-10. Operator Comparison
Category | Java | C# |
|---|---|---|
Arithmetic | + - * / % | + - * / % |
Logical | && || | && || true false |
Bitwise | & | ^ ! ~ | & | ^ ! ~ |
String concatenation | + += | + += |
Increment and decrement | ++ -- | ++ -- |
Bitwise shift | << >> ⋙ | << >> |
Relational | == != < > <= >= | == != < > <= >= |
Assignment | = += -= *= /= %= &= |= ^= <<= >>= ⋙= | = += -= *= /= %= &= |= ^= <<= >>= |
Member access | . | . |
Indexing | [] | [] |
Cast | () | () |
Conditional | ?: | ?: |
Delegate concatenation and removal | N/A | + - |
Object creation | new | new |
Type information | instanceof | is sizeof typeof |
Overflow exception control | N/A | checked unchecked ... |
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