arrays - C# assigning variables -
i found bothers me, great if 1 of explain me. maybe question asked before, i'm out of ideas how name it. here's problem:
array1 = {1,2,3,4,5}; array2 = array1; array1[0] = 10 console.writeline(array2[0]); // - "10" besides of "1"
and when use normal variables instead of arrys, like, ie:
int = 5; int b = a; = 10; console.writeline(b); // - 1 have value "5" instead of 10.
i know how copy arrys values, i'm curious why works that.
the variable array1 not have value 1 or 'c', instead holds address points place in memory data stored.
so array2 = array1 giving array2 same address array1... both point same place.
if want allocate new chunk of memory, you'd have declare new array: int[] array2 = new int[5]; reserves 5*32 bits in memory new array , gives array2 address of first bit.
Comments
Post a Comment