My problem is about an object not set to an instance after the first line inside the foreach loop. I really had a hard time thinking what should be instantiated here. So please guys, i just want to map the data from the DataTable to the a new List.
It errors out after this line,
aa.fieldParams[counter].field = row["ParameterField"].ToString();
Here is my actual code.
public class ParsedData
{
public static void ParseData(DataTable parsedData)
{
ObjectProperties aa = new ObjectProperties();
int counter = 0;
foreach (DataRow row in parsedData.Rows)
{
//parsedData.Rows = new DataTable[parsedData.Rows.Count];
aa.fieldParams[counter].field = row["ParameterField"].ToString();
aa.fieldParams[counter].parameterType = row["ParameterType"].ToString();
aa.fieldParams[counter].length = Convert.ToInt32(row["ParameterLength"]);
aa.fieldParams[counter].setIteration = Convert.ToInt32(row["NumberOfIterations"].ToString());
counter++;
}
}
}
Here is the ObjectProperties class.
public class ObjectProperties
{
public FieldParameters[] fieldParams { get; set; }
public int Counter { get; set; }
}
public class FieldParameters
{
public string field { get; set; }
public int length { get; set; }
public int setIteration { get; set; }
public string parameterType { get; set; }
}
aa.fieldParams[] do not have any values yet because the values of this will be coming from the parsedData.Rows. I am currently having the correct values on row but after the first line inside the loop it errors out.
parsedData values are coming from CSV file.