Problem with copying arrays.
Posted
by Machta
on Stack Overflow
See other posts from Stack Overflow
or by Machta
Published on 2010-04-18T16:28:50Z
Indexed on
2010/04/18
16:33 UTC
Read the original article
Hit count: 262
I have the following code:
string[] firstarray = { "bla bla", "bla bla", "bla bla"};
string[] secondArray = {"aaaaaaaaaaaa", "aaaaaaaaaaa", "aaaaaaaaa"};
string[] newArray = array;
array = secondArray;
foreach (string item in newArray)
{
Console.WriteLine(item);
}
This code gives the following results:
bla bla
bla bla
bla bla
I can't understand why the newArray has the same conntent after I assign a different instance to the array. Please help me.
© Stack Overflow or respective owner