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 拜年红包的祝福语简短
18 妈妈生日祝福语简短励志