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 朋友搬迁新房祝福语简短