2048

  • 用参数改变二维数组(引用数据类型)里的项直接改变原数组
  • 如果是基本数据类型改变参数不会改变原字段

改变原数组

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

public class Test
{
static void Main1()
{
int[,] i = { { 1 } };
int[,] q = TestNum(i);
Console.WriteLine(i);
}

private static int[,] TestNum(int[,] num)
{
num[0, 0] += 1;
return num;
}
}

不改变原数组

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public class Test
{
static void Main()
{
int i = 1;
int q = TestNum(i);
Console.WriteLine(i);
}

private static int TestNum(int num)
{
num += 1;
return num;
}
}