using System; namespace class1 { class program { static void Main(string[] args) { Console.Write("請輸入a="); double a = double.Parse(Console.ReadLine()) ...
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()); Console.WriteLine("First"); Console.Write("\t{0} {1}", a, b); Swap(a,b); Console.WriteLine("\nSecond"); Console.WriteLine("\t{0} {1}" ,a,b); Swap1(ref a, ref b);//實際參數也加上REF Console.WriteLine("\nThird"); Console.WriteLine("\t{0} {1}", a, b); Console.Write("請輸入r="); double r = double.Parse(Console.ReadLine()); double s = MianJiZhouChang(r, out double c);//這裡的out也可以用ref代替,這個時候要為c賦初值 Console.WriteLine("面積是{0},周長是{1}",s,c); } static void Swap(double x, double y) { double z = x; x = y; y = z; } /// <summary> /// 使形式參數變成引用傳遞,加上REF /// </summary> /// <param name="x"></param> /// <param name="y"></param> static void Swap1(ref double x, ref double y) { double z = x; x = y; y = z; } /// <summary> /// OUT應用 /// </summary> /// <param name="r"></param> /// <param name="ZHOUCHANG"></param> /// <returns></returns> static double MianJiZhouChang(double r,out double ZHOUCHANG) { double S = Math.PI * r * r; ZHOUCHANG = 2 * Math.PI * r; return S; } } }