C# operators

In this chapter you will learn:

  1. What are the C# operators
  2. Operators and its categories

Get to know C# operators

C# has the following operators.

Operator symbolOperator nameUser- overloadable
()GroupingNo
.Member accessNo
->Pointer to structNo
()Function callNo
[]Array/indexVia indexer
++Post-incrementYes
--Post-decrementYes
newCreate instanceNo
stackallocUnsafe stack allocationNo
typeofGet type from identifierNo
checkedIntegral overflow check onNo
uncheckedIntegral overflow check offNo
sizeofGet size of structNo
+Positive value ofYes
-Negative value ofYes
!NotYes
~Bitwise complementYes
++Pre-incrementYes
--Pre-decrementYes
()CastNo
*Value at addressNo
Address of valueNo
*MultiplyYes
/DivideYes
%RemainderYes
+AddYes
-SubtractYes
<<Shift leftYes
>>Shift rightYes
<Less thanYes
>Greater thanYes
<=Less than or equal toYes
>=Greater than or equal toYes
isType is or is subclass ofNo
asType conversionNo
==EqualsYes
!=Not equalsYes
&AndYes
^Exclusive OrYes
|OrYes
&&Conditional AndVia &
||Conditional OrVia |
??Null coalescingNo
?:ConditionalNo
=AssignNo
*=Multiply self byVia *
/=Divide self byVia /
+=Add to selfVia +
-=Subtract from selfVia -
<<= Shift self left byVia <<
>>=Shift self right byVia >>
&=And self byVia &
^=Exclusive-Or self byVia ^
|=Or self byVia |
=>LambdaNo

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:

  1. How to use Arithmetic Operators
  2. How to handle Divide by zero exception
Home » C# Tutorial » 
C# operators
Arithmetic Operators
Assignment Operator
Remainder operator
Increment operator and decrement operators
Logic operators
Logic operator shortcut
Relational operators
sizeof
Ternary operator(The ? Operator)
typeof
Bitwise Operators
bitwise AND
bitwise OR
bitwise NOT
bitwise exclusive OR
Shift Operators
Precedence of the C# Operators