I have this code in my gymInfo class:
public class gymInfo
{
public gymArray getAllGymsByStars()
{
gymDataTableAdapters.gymsTableAdapter gymsTableAdapter = new gymDataTableAdapters.gymsTableAdapter();
DataTable gymsDataTable = gymsTableAdapter.getAllGymsByStars();
gymArray gymArray = new gymArray();
foreach(DataRow row in gymsDataTable.Rows)
{
gymArray.name = row["name"].ToString();
}
return gymArray;
}
}
The gymsDataTable
contains 20 rows of names, now I have made a custom class, here is the code:
public class gymArray
{
public string name { get; set; }
}
Which I expected the string name
to get populated with 20 names (as their is 20 rows in the datatable) however when I debug on line return gymArray
it only shows the name of the last row rather than showing a whole custom array of names.
Does anyone understand what I'm doing wrong?