Primary | x.y | Dot operator [1] Used to specify the member of an object/class “ x is the object, y is the member |
f(x) | Used to list the arguments or parameters to a method “ f is the method name , and x represents the method parameter(s) |
a[x] | Used to index an array or an C# indexer (see Chapter 21) |
x++ | Post increment operator Same as Java |
x-- | Post decrement operator Same as Java |
new | new operator Used to create an instance of a class “ besides being an operator keyword, note that the new keyword can also be used as a modifier in C# for name hiding (see section 7.11) |
typeof | typeof operator Returns the System.Type object representing the type of the object it is applied to “ similar to java.lang.Object 's getClass() method |
checked | checked operator Control overflow checking for mathematical operations “ no equivalent in Java |
unchecked | unchecked operator Control overflow checking for mathematical operations “ no equivalent in Java |
Unary | + | Unary plus Same as Java “ example: +3 |
- | Unary minus Same as Java “ example: -3 |
! | (Boolean) logical negation operator Only to be used on boolean values “ returns true or false only. Same as Java's ! operator |
~ | Bitwise complement operator Only to be used on the following C# simple types “ int , uint , long , ulong . Same as Java's ~ operator |
++x | Prefix increment operator Same as Java |
--x | Prefix decrement operator Same as Java |
(T)expression | Cast operator Used to explicitly cast an expression into another type “ T denotes the new type. Same as Java |
Multiplicative | * | Mathematical multiplication (also used for dereferencing pointers in unsafe codes) Same as Java |
/ | Mathematical integral division Same as Java |
% | Mathematical remainder ( modulus ) Same as Java |
Additive | + | Mathematical addition (binary add) Same as Java |
- | Mathematical subtraction (binary minus) Same as Java |
Shift | << | (Bitwise) Left-shift operator Same as Java |
>> | (Bitwise) Right-shift operator [2] Same as Java |
Relational and type testing | < | Smaller-than operator Same as Java |
> | Bigger-than operator Same as Java |
< = | Smaller-than or equals operator Same as Java |
> = | Bigger-than or equals operato Same as Java |
is | is operator Used to check if an object is of a particular type “ similar to Java's instanceof operator |
as | as operator Can be viewed as a combination of the is operator and a cast “ no equivalent in Java |
Equality | == | Equality operator Slightly different from Java's == when used to compare string objects “ otherwise very similar to Java's == operator |
! = | Inequality operator Because the == operator behaves slightly differently in C# and Java, the ! = operator, which returns the complementary result of the == operator is also different “ returns the complementary result of the == operator |
Bitwise/boolean AND | & | &-operator Like Java, can be used for both bool (boolean AND) and integral (bitwise AND) types |
Bitwise/boolean XOR | ^ | XOR operator Like Java, can be used for both bool (boolean AND) and integral (bitwise AND) types |
Bitwise/boolean OR | | operator Like Java, can be used for both bool (boolean AND) and integral (bitwise AND) types |
Conditional AND (also known as short-circuit boolean AND) | && | Conditional & operator Similar to Java's && operator “ will only evaluate second operand if first operand is true. Like Java's && , this operator applies only for bool types (not for integral types) |
Conditional OR (also known as short-circuit boolean OR) | | Conditional operator Similar to Java's operator “ will not evaluate second operand if first operand is true. Like Java's , this operator applies only for bool types (not for integral types) |
Conditional | ?: | Conditional operator Only operator which requires three operands (hence, also popularly known as the 'ternary operator') “ same as Java's ternary operator |
Assignment [3] | = | Assignment operator Same as Java |
* = | Multiplication assignment operator Same as Java |
/ = | (Integral) Division assignment operator Same as Java |
% = | Remainder assignment operator Same as Java |
+= | Addition assignment operator Same as Java |
- = | Subtraction assignment operator Same as Java |
<< = | Left shift assignment operator Same as Java |
>> = | Right shift assignment operator Same as Java |
& = | AND assignment operator Same as Java |
^ = | XOR assignment operator Same as Java |
= | OR assignment operator Same as Java |
Additional C# operators used for unsafe code (see Chapter 29): |
Operators for unsafe coding | * | Pointer operator Used to declare pointer types and for dereferencing pointers (same symbol is used as the mathematical multiplication operator) “ no equivalent in Java |
& | Address of operator Used to retrieve the address of a particular object (same symbol is used as the bitwise and boolean AND operator) “ no equivalent in Java |
sizeof | sizeof operator Returns the size (number of bytes) of a simple type or other structs “ no equivalent in Java |
- | Member-of operator Used for accessing a member of a class via pointers, like the . operator “ Can only be applied to a pointer type. No equivalent in Java |