C#中的赋值运算符是什么?
运算符是一个符号,告诉编译器执行特定的数学或逻辑操作。
以下是C#中的赋值运算符。
示例
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();
}
}
}输出结果
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