能否告诉我如何将2维数组列表复制到另一个数组列表而不引用相同的数组实例?如何将2D数组列表复制到另一个
void partial_entropy(List<List<String>> class_lables)//This 2D "class_lables" arraylist contains many elements
{
List<List<String>> lables1 = new List<List<String>>();
lables1 = class_lables; //copying old arraylist to new array list called "lables1"
//if I copy using the above method, both refer to same array instance.
//Therefore, I would like to use something like "CopyTo" method
class_lables.CopyTo(lables1, 0);//This did not work
for (int x = 0; x < lables1.Count; x++)//To print out the newly copyed 2D array
{
for (int y = 0; y < 1; y++)
{
Console.Write(lables1[x][y]+" ");
Console.WriteLine(lables1[x][y+1]);
}
}
}
最坏的情况下,你可以通过class_lables循环,并添加项目lables1 – Gowtham 2014-10-06 06:12:51