I'm using a for
loop to read the lines of a file one by one. I then use the data in each line of the file to change the properties of the objects in an array.
I've run through the code in Debug mode, and it all seems to run fine. It reads the line of the file which corresponds to the i
value of the for loop correctly, it defines an array of this data based on the commas, and it creates a temporary object which stores these values in the correct format. I know all of this because, as I've said, I have checked the values in Debug mode.
However, on the last line inside of the loop it seems to change every element in the array to the values stored in scrOldScore
, whereas I want it to keep the values that it read in from
previous lines and just update the element of the array corresponding to the i
of the for loop.
With each iteration of the for loop, the array holds identical data in each element that isn't null, and with each iteration that data changes to the most recently defined scrOldScore
.
string str;
Data d = new Data();
for (int i = 0; i < arr.Length; i++)
{
str = File.ReadLines(FileName).Skip(i).Take(1).First(); ;
string[] string = new string[4];
string = str.Split(',');
d.Property01 = string[0];
d.Property02 = Convert.ToInt32(string[1]);
d.Property03 = string[2];
d.Property04 = string[3];
arr[i] = d;
}
Thanks for any help :)