I would like to create a multidimensional list with the following data
How do I initialize the list and a new class?
I am trying to do the following but when I start adding data how can I link a tyreID
to a vehicleID
? Should I create two classes?
public class ListName
{
public int vehicleID { get; set; }
public string tyresID { get; set; }
}
List<ListName> manID = new List<ListName>();
Edit: Thank you for the answers but I am struggling to adapt your suggestions to the following. It is the same logic but I do not find an easy way to write the data into the lists
public class criterias
{
public double values { get; set; }
public double time { get; set; }
}
public class movChannels
{
public string name { get; set; }
public IList<criterias> criteria = new List<criterias>();
}
public class stepsList
{
public string steps { get; set; }
public IList<movChannels> stepChannelsCriteria = new List<movChannels>();
}
public class vehicles
{
public int vehID { get; set; }
public string vehDescription { get; set; }
public IList<stepsList> vehValCriteria = new List<stepsList>();
}
Now, how can I add the data the I have in the table shown into a list called Vehicles?
You can create a couple classes to represent Tyre and Vehicle:
public class Tyre
{
public int Id { get; set; }
}
public class Vehicle
{
public string Id { get; set; }
public IList<Tyre> Tyres { get; set; } = new List<Tyre>();
}
Something like this:
var vehicles = new[]
{
new Vehicle
{
Id = "XPT1",
Tyres = new[]
{
new Tyre {Id = 23},
new Tyre {Id = 15},
}
},
new Vehicle
{
Id = "OUW2",
Tyres = new[]
{
new Tyre {Id = 212},
new Tyre {Id = 15},
}
}
};
Why not like this?
public class ListName
{
public int vehicleID { get; set; }
List<string > TireIds = new List<string>();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.