Given this example:
// Create an arary of car objects.
car[] arrayOfCars= new car[]
{
new car("Ford",1992),
new car("Fiat",1988),
new car("Buick",1932),
new car("Ford",1932),
new car("Dodge",1999),
new car("Honda",1977)
};
I tried something like this:
for (int i = 0; i < dtable.Rows.Count; i++)
{
DataRow drow = dtable.Rows[i];
arrayOfCars[] = new car(drow["make"].ToString(), drow["year"].ToString());
}
How do I add additional data to the array while looping through a datatable?
UPDATE1:
I went with the solution proposed by @Reed.
// Create the array, specifying the total length
car[] arrayOfCars = new car[dtable.Rows.Count];
for (int i = 0; i < dtable.Rows.Count; i++)
{
DataRow drow = dtable.Rows[i];
// Assign each car to the specific index within the array (arrayOfCars[i])
arrayOfCars[i] = new car(drow["make"].ToString(), drow["year"].ToString());
}