Frequently used operators
For more information, see a C# or Java programming reference.
Frequently used operators
Operator category |
Operator |
Use |
Description |
---|---|---|---|
Arithmetic |
+ |
x + y |
Adds x and y. |
|
- |
x - y |
Subtracts y from x. |
|
* |
x * y |
Multiplies x by y. |
|
/ |
x / y |
Divides x by y. |
|
% |
x % y |
Returns the remainder of integer division of x and y. |
Logical (Boolean and bitwise) |
& |
x & y |
Evaluates both x and y and returns the logical conjunction ("AND") of their results. If x and y are integers, the logical conjunction is performed bitwise. |
|
| |
x | y |
Evaluates x and y and returns the logical disjunction ("OR") of their results. If x and y are integers, the logical disjunction is performed bitwise. |
|
^ |
x ^ y |
Returns the exclusive or ("XOR") of their results. If x and y are integers, the exclusive or is performed bitwise. |
|
! |
!x |
Evaluates x and returns the negation ("NOT") of the result.
|
|
~ |
~x |
Evaluates x and returns the bitwise negation of the result. ~x returns a value where each bit is the negation of the corresponding bit in the result of evaluating x. |
|
&& |
x && y |
Evaluates x.
Note that if evaluating y would hypothetically have no side effects, the results are identical to the logical conjunction performed by the & operator. |
|
|| |
x || y |
Evaluates x.
Note that if evaluating y would hypothetically have no side effects, the results are identical to the logical disjunction performed by the | operator. |
|
( ) |
|
Used to group information. |
String concatenation |
+ |
x + y |
Concatenates strings. |
Relational |
== |
x == y |
|
|
!= |
x != y |
Returns the logical negation of the operator ==.
|
|
< |
x < y |
|
|
> |
x > y |
|
|
<= |
x <= y |
|
|
>= |
x >= y |
|
Member access |
. |
this.Value |
Used to form long names. |
Indexing |
[ ] |
|
Used to access array elements. |
Conditional |
?: |
x ? y : z |
|
Assignment |
= |
x = y |
Assigns the value of y to x. |