I have some strange problem where all my string arrays has the same value in the List. Here is my code:
List<string[]> map_data = new List<string[]>();
string[] map_data_array = new string[11];
for(int i = 0; i < 2000; i++)
{
map_data_array = PopulateDataFromFile(); // it returns different data every call
map_data.Add(map_data_array); // store to List
}
map_data_array has always different data, I've verified that by placing the break point there and I've checked it.
The problem is that map_data
has the value of all elements the same. And this value is the data that comes from function PopulateDataFromFile
when the i is 1999.
What I am doing wrong? :/
PopulateDataFromFile()
as well – aiapatag Jun 18 at 11:01map_data[0] == map_data[1999]
if it returnstrue
you are adding the same array 2000 times (that isPopulateDataFromFile()
returns the same array if it returnsfalse
thenPopulateDataFromFile()
returns a new array every time but with the4 same content – Rune FS Jun 18 at 11:04