C# = assigning custom objects to array with a for loop?
Posted
by John M
on Stack Overflow
See other posts from Stack Overflow
or by John M
Published on 2010-06-14T18:49:02Z
Indexed on
2010/06/14
18:52 UTC
Read the original article
Hit count: 229
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?
© Stack Overflow or respective owner