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

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

c# - Unity IoC Lifetime per HttpRequest for UserStore -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -