Operator एक Symbol है जो Compiler को Specific Mathematical या Logical Manipulations Perform करने के लिए कहता है।
C# में निम्न Assignment Operators हैं।
| Operator | Description | Example |
|---|---|---|
| = | Simple Assignment Operator, Right Side Operands से Values को Left Side Operand में Assign करता है | C = A + B, A + B की Value को C में Assign करता है |
| += | Add AND Assignment Operator, Right Operand को Left Operand में Add करता है और Result को Left Operand में Assign करता है | C += A, C = C + A के Equivalent है |
| -= | Subtract AND Assignment Operator, Right Operand को Left Operand से Subtract करता है और Result को Left Operand में Assign करता है | C -= A, C = C - A के Equivalent है |
| *= | Multiply AND Assignment Operator, Right Operand को Left Operand से Multiply करता है और Result को Left Operand में Assign करता है | C *= A, C = C * A के Equivalent है |
| /= | Divide AND Assignment Operator, Left Operand को Right Operand से Divide करता है और Result को Left Operand में Assign करता है | C /= A, C = C / A के Equivalent है |
| %= | Modulus AND Assignment Operator, दो Operands का Modulus लेता है और Result को Left Operand में Assign करता है | C %= A, C = C % A के Equivalent है |
| <<= | Left Shift AND Assignment Operator | C <<= 2, C = C << 2 के Same है |
| >>= | Right Shift AND Assignment Operator | C >>= 2, C = C >> 2 के Same है |
| &= | Bitwise AND Assignment Operator | C &= 2, C = C & 2 के Same है |
| ^= | Bitwise Exclusive OR और Assignment Operator | C ^= 2, C = C ^ 2 के Same है |
| |= | Bitwise Inclusive OR और Assignment Operator | C |= 2, C = C | 2 के Same है |
Example
using System; namespace Demo { class Program { static void Main(string[] args) { int a = 21; int c; c = a; Console.WriteLine("Value of c = {0}", c); c += a; Console.WriteLine("Value of c = {0}", c); c -= a; Console.WriteLine("Value of c = {0}", c); c *= a; Console.WriteLine("Value of c = {0}", c); c /= a; Console.WriteLine("Value of c = {0}", c); c = 200; c %= a; Console.WriteLine("Value of c = {0}", c); c <<= 2; Console.WriteLine("Value of c = {0}", c); c >>= 2; Console.WriteLine("Value of c = {0}", c); c &= 2; Console.WriteLine("Value of c = {0}", c); c ^= 2; Console.WriteLine("Value of c = {0}", c); c |= 2; Console.WriteLine("Value of c = {0}", c); Console.ReadLine(); } } }Output
Value of c = 21 Value of c = 42 Value of c = 21 Value of c = 441 Value of c = 21 Value of c = 11 Value of c = 44 Value of c = 11 Value of c = 2 Value of c = 0 Value of c = 2