using System; namespace class1 { class program { static void Main(string[] args) { //值傳遞引用,實際參數不會變化 Console.Write("請輸入a="); double a = double.Parse(Co ...
using System; namespace class1 { class program { static void Main(string[] args) { //值傳遞引用,實際參數不會變化 Console.Write("請輸入a="); double a = double.Parse(Console.ReadLine()); Console.Write("請輸入b="); double b = double.Parse(Console.ReadLine()); double c = max(a, b);//局部實際參數 Console.WriteLine("您輸入的值中比較大的是{0}", c); //地址傳遞引用,實際參數會變化 int[] ex = new int[4] { 1, 2, 3, 4 }; Console.WriteLine("Before"); foreach (var item in ex) { Console.Write("\t{0}", item); } dou(ex); Console.WriteLine("\nEnd"); foreach (var item in ex) { Console.Write("\t{0}", item); } } /// <summary> /// 值傳遞 /// </summary> /// <param name="a">形式參數(參數為值類型)</param> /// <param name="b">形式參數(參數為值類型)</param> /// <returns></returns> static double max(double a, double b) {//局部形式參數 double c = a > b ? a : b; return c; } /// <summary> /// 地址傳遞 /// </summary> /// <param name="array">數組參數(參數為引用類型)</param> static void dou(int[] array) { for (int i = 0; i < array.Length; i++) { array[i] = array[i] * 2; } } } }