要将同一值分配给一行中的多个变量,请使用=运算符-
val1 = val2 = 20;
上面的语句将20分配给变量val1和val2,如以下代码所示-
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Demo { class MyApplication { static void Main(string[] args) { int val1, val2; val1 = val2 = 20; Console.WriteLine("Value1 = "+val1); Console.WriteLine("Value2 = "+val2); } } }
输出结果
Value1 = 20 Value2 = 20