参考: 李志. Learning hard C#学习笔记 (图灵原创) (p. 86). 人民邮电出版社. Kindle 版本.
1 static void TestOut(out int a) 2 { 3 a = 12; //out 修饰符如果不赋值 就会导致 编译器报错 4 Console.WriteLine("func a :" + a.ToString()); 5 } 6 static void TestRef(out int a) 7 { 8 a = 12; //ref可以不赋值使用 9 Console.WriteLine("func a :" + a.ToString()); 10 } 11 12 static void Main(string[] args) 13 { 14 int ta = 0; 15 TestOut(out ta); 16 Console.WriteLine("a:" + ta.ToString()); 17 18 Console.ReadKey(); 19 }