Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Assigning an array to another array
Message
From
15/11/2004 12:59:51
 
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00961244
Message ID:
00961445
Views:
4
Gerard,

As a follow-up to my last reply to you, look up either "value type" or "reference type" in Visual Studio's Help. There are some decent explanations and examples of the two types.

~~Bonnie


>Hi Bonnie.Thanks for yuor reply.
>
>That makes sense, but probably a bit more difficult to implement than VFP.
>For the other types, can I say a=b and get a 'Copy' for e.g.
>
>lcMyStringB = lcMyStringA
>lnMyNumB = lnMyNumA (For each of numeric types)
>llMyBoolB = llMyBoolA
>loMyObjB = loMyObjA
>etc.
>
>In above examples, is a 'Copy' made or a 'Reference'
>
>Regards,
>
>Gerard
>
>
>>Gerard,
>>
>>This is because the arrays are really object pointers (as are most things in .NET ... an integer itself isn't, but an array of them are). When you assign your 1st array to your 2nd array, you're merely assigning the pointers, so that my_array2 *is* my_array and not merely a copy. I assume you wanted a copy of my_array, and so you need to use the Array.Copy() method.
>>
>>~~Bonnie
>>
>>
>>
>>>I have following:
>>>public int [] my_array = [1,2,3,4,5}
>>>
>>>Then in a method I have
>>>int[] my_array2
>>>my_aary2 = my_array
>>>
>>>But if I amend my_array subsequently, my_array2 is also amended
>>>
>>>Anybody know why this is happening and if there is a way around it ?
>>>
>>>Regards,
>>>
>>>Gerard
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Reply
Map
View

Click here to load this message in the networking platform