Csharp/CSharp Tutorial/Operator/Assignment Operator
Содержание
Full list of shortcut assignment operators available in C#.
<source lang="csharp">Shortcut Operator Equivalent To x++, ++x x=x+1 x--, --x x=x-1 x+=y x=x+y x-=y x=x-y x*=y x=x*y x/=y x=x/y x%=y x=x%y x>>= y x=x>>y x<<= y x=x<<y x&=y x=x&y x|=y x=x|y x^=y x=x^y</source>
List of Compound Operators
<source lang="csharp">Operator Symbol Sample Addition Assignment += variable+=5; Subtraction Assignment -= variable-=10; Multiplication Assignment *= variable*=5; Division Assignment /= variable/=5; Modulus Assignment %= variable%=3; And Assignment &= variable&=3; Or Assignment |= variable|=3; XOR Assignment ^= variable^= 3; Left-Shift Assignment <<= variable<<=3; Right-Shift Assignment >>= variable>>=1</source>
Operator list
<source lang="csharp">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 ??</source>
The Assignment Operator
It has this general form:
<source lang="csharp">var = expression;</source>