Reputation: 2813
I have inflation rates stored in a database with the following structure:
When reading the above data, I need to initialize business objects with a different structure dynamically and fill them with the database data.
If the database would be like the above, I would need to create two objects: "UK Inflation Forecast" and "Germany Inflation Forecast". In this case, both objects would have 6 properties: CountryName (as String) and 5 inflation values (as Double).
How can I create the object classes without knowing the number of properties needed and how do I fill these with data?
Upvotes: 0
Views: 115
Reputation: 2337
I would say create a class of the following structur:
public class InflationClass
{
public InflationClass()
{
InflationValues = new Dictionary<int, double>();
}
public string Country { get; set; }
public Dictionary<int, double> InflationValues { get; private set; }
}
And load the data like so
int sampleYear = 2016;
double sampleValue = 123456789.01;
var inflation = new InflationClass();
if(!inflation.InflationValues.ContainsKey(sampleYear ))
{
inflation.InflationValues.Add(sampleYear , sampleValue);
}
I've used C# but this can easily be converted to VB.NET if you prefer.
Upvotes: 1