如何在C#中使用赋值运算符?
使用C#中的赋值运算符将值赋给变量-
以下是C#中的赋值运算符-
以下是一个例子-
示例
using System; namespace OperatorsAppl { class Program { static void Main(string[] args) { int a = 21; int c; c = a; Console.WriteLine("Assignment Operator: {0}", c); c += a; Console.WriteLine("+= Value: {0}", c); c -= a; Console.WriteLine("+= Value: {0}", c); c *= a; Console.WriteLine("*= Value: {0}", c); c /= a; Console.WriteLine("/= Value: {0}", c); c = 200; c %= a; Console.WriteLine("%= Value: {0}", c); c <<= 2; Console.WriteLine("<<= Value: {0}", c); Console.ReadLine(); } } }
输出结果
Assignment Operator: 21 += Value: 42 += Value: 21 *= Value: 441 /= Value: 21 %= Value: 11 <<= Value: 44