C# operators
In this chapter you will learn:
Get to know C# operators
C# has the following operators.
Operator symbol | Operator name | User- overloadable |
---|---|---|
() | Grouping | No |
. | Member access | No |
-> | Pointer to struct | No |
() | Function call | No |
[] | Array/index | Via indexer |
++ | Post-increment | Yes |
-- | Post-decrement | Yes |
new | Create instance | No |
stackalloc | Unsafe stack allocation | No |
typeof | Get type from identifier | No |
checked | Integral overflow check on | No |
unchecked | Integral overflow check off | No |
sizeof | Get size of struct | No |
+ | Positive value of | Yes |
- | Negative value of | Yes |
! | Not | Yes |
~ | Bitwise complement | Yes |
++ | Pre-increment | Yes |
-- | Pre-decrement | Yes |
() | Cast | No |
* | Value at address | No |
Address of value | No | |
* | Multiply | Yes |
/ | Divide | Yes |
% | Remainder | Yes |
+ | Add | Yes |
- | Subtract | Yes |
<< | Shift left | Yes |
>> | Shift right | Yes |
< | Less than | Yes |
> | Greater than | Yes |
<= | Less than or equal to | Yes |
>= | Greater than or equal to | Yes |
is | Type is or is subclass of | No |
as | Type conversion | No |
== | Equals | Yes |
!= | Not equals | Yes |
& | And | Yes |
^ | Exclusive Or | Yes |
| | Or | Yes |
&& | Conditional And | Via & |
|| | Conditional Or | Via | |
?? | Null coalescing | No |
?: | Conditional | No |
= | Assign | No |
*= | Multiply self by | Via * |
/= | Divide self by | Via / |
+= | Add to self | Via + |
-= | Subtract from self | Via - |
<<= | Shift self left by | Via << |
>>= | Shift self right by | Via >> |
&= | And self by | Via & |
^= | Exclusive-Or self by | Via ^ |
|= | Or self by | Via | |
=> | Lambda | No |
Operators and its categories
Category Operator
Arithmetic +-*/%
Logical &|^~&&||!
String concatenation +
Increment and decrement ++ --
Bit shifting << >>
Comparison == != <> <= >=
Assignment =+=-=*=/=%=&=|=^=<<=>>=
Member access (for objects and structs) .
Indexing (for arrays and indexers) []
Cast ()
Conditional (the Ternary Operator) ?:
Delegate concatenation and removal +-
Object Creation new
Type information sizeof (unsafe code only) is typeof as
Overflow exception control checked unchecked
Indirection and Address *->& (unsafe code only) []
Namespace alias qualifier ::
Null coalescing operator ??
Next chapter...
What you will learn in the next chapter:
Home » C# Tutorial »