Hi Everyone,
I was wondering if someone could help me. I am receiving data from an XML response stream. The data that I am receiving is in the form of an array. I need to take this data and insert it into a new array. I am not sure how to go about this. I think I need to count the items in the array I am receiving and then use a while statement to add the items to the new array. I am not sure though. Could someone please point me in the right direction? Thanks in advance!
Jay
AlanPosted Sep 4, 2008, 3:51 PM
If the data is already in the form of an array (oldArray say), then you can in fact assign it directly to another array in C#. For example:
string[] newArray = oldArray;
Now both arrays contain exactly the same string elements. However, if you change an element in oldArray then it will automatically change the corresponding element in newArray because they're the same array object.
If you want an independent copy (i.e. a clone) then you can do this instead:
string[] newArray = (string[])oldArray.Clone();
The cast is needed because the Clone method returns an 'object'.
Changing an element in oldArray will not now change the corresponding element in newArray and vice versa.
JayPosted Sep 5, 2008, 8:27 AM