I want to user a foreach loop to add to a c# list without using the list properties Key name.
I have a list such as
public class Bus
{
public string Val1 { get; set; }
public string Val2 { get; set; }
public string Val3 { get; set; }
public string Val4 { get; set; }
public string Val5 { get; set; }
public string Val6 { get; set; }
// ...
public string Val127 { get; set; }
}
The lists I want to populate can have over 200 properties so I am trying to find a quick way to populate them without writing out the properties. I want to populate this from a one dimensional array (line) using something like this
j = 0
for (int i = 0; i < lines.Length; i++)
{
foreach(Bus BusProp in BusList)
{
BusProp[j] = line[i+j];
j =+ 1;
}
}
This is not working. Any suggestions are appreciated