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
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短