下面是我看到的js参数传递的方法,其中说js只有按值传递 以上是我在《javascript高级程序设计》中看到的。然后我用C#写了下面这段代码using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace refTest{ class Program { static void SomeFunction(int[] ints, int i) { ints[0] = 100; ints = new int[] { 3, 4, 5, 9, 8 }; i = 100; } static void Main(string[] args) { int i = 0; int[] ints = { 0, 1, 2, 4, 8 }; Console.WriteLine("i = " + i); Console.WriteLine("ints[0] = " + ints[0]); Console.WriteLine("Call SomeFunction."); SomeFunction(ints, i); Console.WriteLine("i = " + i); Console.WriteLine("ints[0] = " + ints[0]); } }} 结果发现和JS中的情形是一样的,难道C#的引用类型不是按引用传递的吗?
- 2 回答
- 0 关注
- 502 浏览
添加回答
举报
0/150
提交
取消