static int[] scores = new int[100];
static int[] scorescopy;
public static int orderscores()
{
scorescopy = scores;
Array.Sort(scorescopy);
int sortingtoolb = 0;
return 0;
}
我正在尝试获取初始数组的副本,然后尝试对该副本进行排序。但是,当我使用Array.Sort()函数时,我的第一个数组也继续保持排序状态,但是我想保留它。我尝试删除了比分表上的新声明,但这并没有影响结果。
另外,有没有办法将数组中未使用的变量保留为null? (如果我没有使用它的所有部分,则在数组的开头会得到一堆0)。
我在运行Windows 8.1 Pro的系统上使用Windows 8的Visual Studio Express 2012。
最佳答案
您正在获得指向同一数组的指针,您需要一个克隆:
scorescopy = (int [])scores.Clone();
关于c# - 数组影响其他数组值C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22539748/