I have created a class and have four properties and I am reading the values from a CSV file and then assign them to the class properties and then trying to add the object to Arraylist.
But after the loop, the array list has got 5 items, but all items look the same!
What is wrong with the above ? Please help. I am new to C#.
But after the loop, the array list has got 5 items, but all items look the same!
Code:
// declaring the array list
ArrayList objClaimData = new ArrayList();
// creating an instance of the class
clsClaimData datClaims = new clsClaimData();
// declaring the variable for streamreader
string file_name = "D:\\Bhagavan\\My Documents\\Visual Studio 2010\\Projects\\ClaimsReserving\\ClaimsReserving\\claims.csv";
string textLine = "";
string[] colval = null;
// opening the file using the streamreader
System.IO.StreamReader objReader;
objReader = new System.IO.StreamReader(file_name);
// looping thru the text file until all lines are read and stored in the arraylist.
while ((textLine = objReader.ReadLine()) != null)
{
colval = textLine.Split(',');
datClaims.Product = Convert.ToString(colval[0]);
datClaims.OrginYear = Convert.ToInt32(colval[1]);
datClaims.DevYear = Convert.ToInt32(colval[2]);
datClaims.IncrementValue = Convert.ToDouble(colval[3]);
objClaimData.Add(datClaims);
Console.WriteLine(textLine);
}
Comment