c# - How to add an array to a list by value not by reference? -
is there way add array list of arrays value , not reference?
example: following prints out "6, 7, 8, 9, 10". want write out "1, 2, 3, 4, 5".
int[] testarray = new int[5] { 1, 2, 3, 4, 5 }; list<int[]> testlist = new list<int[]>(); testlist.add(testarray); testarray[0] = 6; testarray[1] = 7; testarray[2] = 8; testarray[3] = 9; testarray[4] = 10; foreach(int[] array in testlist) { console.writeline("{0}, {1}, {2}, {3}, {4}", array[0], array[1], array[2], array[3], array[4]); }
make copy:
testlist.add(testarray.toarray());
Comments
Post a Comment