Csharp/CSharp Tutorial/Operator/Assignment Operator
Содержание
Full list of shortcut assignment operators available in C#.
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
List of Compound Operators
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
Operator list
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 ??
The Assignment Operator
It has this general form:
var = expression;