using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Practice805_2 { class Program { public static void Main(string[] args) { Test test = new Test(); //按輸出方式訪問參數 double param = 1; double out1; double out2; double out3; test.method(param, out out1, out out2, out out3); Console.WriteLine(out1); Console.WriteLine(out2); Console.WriteLine(out3); TestRef testR = new TestRef(); //按值 double param1 = 10; double douNotRef = testR.testNotRef(param1); Console.WriteLine("param1::::" + param1); Console.WriteLine(douNotRef); //按引用 double param2 = 10; double douRef = testR.testRef(ref param2); Console.WriteLine("param2::::" + param2); Console.WriteLine(douRef); Console.ReadLine(); } } class TestRef { public double testNotRef(double x) { x = x * x; return x; } public double testRef(ref double y) { y = y * y; return y; } } class Test { public void method(double param, out double out1, out double out2, out double out3) { out1 = param /2; out2 = param / 3; out3 = param / 4; } } }
這裏面介紹了三種參數的訪問屬性,分別爲按值,按引用,以輸出方式訪問參數。比較具體,比java中的值傳遞仍是引用傳遞更明確了。這裏面主要是提到基本類型默認的均爲按值傳遞,若想改成引用,可用ref。out的輸出方式能夠借鑑下java